Be a Supporter!

Sprites Question.

  • 393 Views
  • 17 Replies
New Topic Respond to this Topic
jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Sprites Question. 2009-04-25 17:43:26 Reply

If I make a movie clip set of sprites and say I program him to go left, but want him to go right and face right too and he only faced left before, what could I do to make it so he faces right with out completely remaking the sprites movie clips? Could I just copy the main sprites movie clip and go inside it and put it at the end in the opposite direction?


smiles

FoxtrotZulu
FoxtrotZulu
  • Member since: Apr. 18, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Sprites Question. 2009-04-25 17:49:35 Reply

At 4/25/09 05:43 PM, jackkyboy wrote: If I make a movie clip set of sprites and say I program him to go left, but want him to go right and face right too and he only faced left before, what could I do to make it so he faces right with out completely remaking the sprites movie clips? Could I just copy the main sprites movie clip and go inside it and put it at the end in the opposite direction?

You can edit the _xscale property of a MovieClip.
For example, if you're MovieClip's instance name was "player", you would use the code:
player._xscale = -100

Then, to reset him, use (notice I used a negative symbol before):

player._xscale = 100

Tell me if this helps. If not, I'll try to help further.

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:04:54 Reply

okay well here is part of my code and his instance name is player, would this be correct because It most certainly did not reverse the clip. and didnt do anything

if(Key.isDown(Key.LEFT)){
_x-=speed;
player._xscale=100;
}


smiles

Doomsday-One
Doomsday-One
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Sprites Question. 2009-04-25 18:07:33 Reply

At 4/25/09 06:04 PM, jackkyboy wrote: if(Key.isDown(Key.LEFT)){
_x-=speed;
player._xscale=100;
}

If he moves left when you press left, then remove the 'player.' bit. That bit is needed for referencing, when you're coding on the main timeline for example. Yet, where you're placing the code does not need this referencing. You just need the '_xscale'.


Doomsday-One, working on stuff better than preloaders. Marginally.

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:12:59 Reply

Okay it works now, thanks so much! now I can get farther on my game!


smiles

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:15:04 Reply

Hmm now, even when I let go of the key, he still does the animation for walking! what should I do now.

here is a tidbit of the code

if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
_root.player.gotoAndStop(2);
}


smiles

FoxtrotZulu
FoxtrotZulu
  • Member since: Apr. 18, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Sprites Question. 2009-04-25 18:16:28 Reply

I said -100 reverses him and 100 puts him back to normal.

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:19:46 Reply

Yeah he turns fine, It's just he just walks now and doesnt stop


smiles

Doomsday-One
Doomsday-One
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Sprites Question. 2009-04-25 18:20:33 Reply

At 4/25/09 06:15 PM, jackkyboy wrote: if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
_root.player.gotoAndStop(2);
}

else {
_root.player.gotoAndStop(1)
}

...Or whatever frame the stationary animation is on.


Doomsday-One, working on stuff better than preloaders. Marginally.

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:35:14 Reply

well it works, it jsut doesnt show the animation for the running, he just slides on the ground instead of any running sequence.


smiles

Doomsday-One
Doomsday-One
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Sprites Question. 2009-04-25 18:39:18 Reply

if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
_root.player.gotoAndStop(2);
} else {
_root.player.gotoAndStop(1);
}

I think you need to learn some more coding, my friend.


Doomsday-One, working on stuff better than preloaders. Marginally.

Captainhams
Captainhams
  • Member since: May. 4, 2008
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Sprites Question. 2009-04-25 18:41:51 Reply

I would suggest going and taking a look at some movement tutorials

Also, judging by your problems it doesn't look like your player mc does actually have the instance name "player" - maybe you should double check that


lawl

BBS Signature
jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:44:15 Reply

At 4/25/09 06:39 PM, Doomsday-One wrote: if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
_root.player.gotoAndStop(2);
} else {
_root.player.gotoAndStop(1);
}

That is the exact code I put in! and It just won't play the clip.


smiles

Doomsday-One
Doomsday-One
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Sprites Question. 2009-04-25 18:49:59 Reply

At 4/25/09 06:41 PM, Captainhams wrote: Also, judging by your problems it doesn't look like your player mc does actually have the instance name "player" - maybe you should double check that

Indeed. Try removing the parts of the code which say '_root.player.'


Doomsday-One, working on stuff better than preloaders. Marginally.

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 18:56:51 Reply

Hmm that did not do it either.

heres the entire code so far.

onClipEvent(load){
var ground:MovieClip=_root.ground;
var grav:Number=0;
var gravity:Number=2;
var speed:Number=10;
var maxJump:Number=-18;
var touchingGround:Boolean=false;
_root.ATTACKONE = 65;
_root.ATTACKTWO = 83;
}
onClipEvent(enterframe){
_y+=grav;
grav+=gravity;
while(ground.hitTest(_x,_y,true)){
_y-=gravity;
grav=0;
}
if(ground.hitTest(_x,_y+1,true)){
touchingGround=true;
}else{
touchingGround=false;
}
if(Key.isDown(Key.RIGHT)){
_x+=speed;
_xscale=-100;
gotoAndStop(2);
}else{
gotoAndStop(1);
}
if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
gotoAndStop(2);
}else{
gotoAndStop(1);
}
if(Key.isDown(Key.UP)&&
touchingGround){
grav=maxJump;
}
}


smiles

Doomsday-One
Doomsday-One
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Sprites Question. 2009-04-25 19:02:40 Reply

At 4/25/09 06:56 PM, jackkyboy wrote: if(Key.isDown(Key.RIGHT)){
_x+=speed;
_xscale=-100;
gotoAndStop(2);
}else{
gotoAndStop(1);
}
if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
gotoAndStop(2);
}else{
gotoAndStop(1);
}

Oh, of course.
Try this:

if(Key.isDown(Key.RIGHT)){
_x+=speed;
_xscale=-100;
gotoAndStop(2);
}else if(Key.isDown(Key.LEFT)){
_x-=speed;
_xscale=100;
gotoAndStop(2);
}else{
gotoAndStop(1);
}

Basically, it was going to frame 1 if the left key wasn't down or the right key wasn't down. So it would only play 'walking' if both were down. I used 'else' statements to stop that.
Now the code checks whether the right key is down. If it isn't, it checks the left. If that isn't either, it goes to the standing animation.


Doomsday-One, working on stuff better than preloaders. Marginally.

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 19:08:04 Reply

Okay! thanks so much I just did some editing to make it work on the other key, and It did it, Thanks so Much!


smiles

jackkyboy
jackkyboy
  • Member since: Aug. 2, 2008
  • Offline.
Forum Stats
Member
Level 06
Game Developer
Response to Sprites Question. 2009-04-25 19:11:40 Reply

OKAY I SWEAR THIS IS THE LAST QUESTION, I have attack clips too, Two to be exact, and I was review a different engine I had. and it said to put

_root.ATTACKONE = 65;
_root.ATTACKTWO = 83;
if(Key.isDown(_root.ATTACKONE)){
_root.player.gotoAndStop(4);
}
if(Key.isDown(_root.ATTACKTWO)){
_root.player.gotoAndStop(5);
}

on the ClipEvent Player

and When I try to use it. nothing happens.


smiles