Be a Supporter!

Walking animation fail

  • 400 Views
  • 5 Replies
New Topic Respond to this Topic
gameObject
gameObject
  • Member since: Jan. 4, 2012
  • Offline.
Forum Stats
Member
Level 03
Game Developer
Walking animation fail 2013-01-20 04:38:45 Reply

Good day newgrounds
I am creating a beat 'em up sidescroller
i'm having trouble with walk animation.
When the player presses the left and right keys, the character's walking animation will player fine
When the player presses the up and down keys, the characters walking animation will now player and remain idle.
Here's what i have.

public function playerMovement(event: Event):void
		{
			if (upKeyDown)
			{
				this.y -=  walkSpeed;
				this.gotoAndStop("playerWalk")
			}
			
			else if (downKeyDown)
			{
				this.y +=  walkSpeed;
				this.gotoAndStop("playerWalk");
			}
			
			if (leftKeyDown)
			{
				this.x -=  walkSpeed;
				this.scaleX = -1;
				this.gotoAndStop("playerWalk");
			}
			
			else if (rightKeyDown)
			{
				this.x +=  walkSpeed;
				this.scaleX = 1;
				this.gotoAndStop("playerWalk");
			}
			else
			{
				this.gotoAndStop("playerIdle");
			}
		}

Will appreciate any help offered
Cheers

tomdeaap
tomdeaap
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to Walking animation fail 2013-01-20 08:20:44 Reply

What you're saying in your code is the following:
"If the up key or the right key is pressed, play the animation. Then in the following bit, if neither the right nor the left key are pressed play idle."

This means that if you press only the up or down keys the statement for putting it on idle is true. There's a couple ways to fix this. You can either put an 'else if up or down isn't pressed' instead of the else you have right now before putting it on idle. Or you can move the block of code involving the up and down key below the left and right key bit. Be weary though, because you might be resetting your animation every frame when doing this (left and right aren't being pressed, so put on idle, then it sees up or down is pressed so it puts it on walking). Therefore the latter will only work when it's a single frame 'animation'.

Be sure to mess around a bit on your own, because there's more than the two ways I mentioned to fix this.


"Insert deep, brain twisting sentence here"

gameObject
gameObject
  • Member since: Jan. 4, 2012
  • Offline.
Forum Stats
Member
Level 03
Game Developer
Response to Walking animation fail 2013-01-24 06:11:28 Reply

Just to not leave you hanging. I'm still trying to make it work. I've tried a billion ways and it still isn't working...

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Walking animation fail 2013-01-24 12:43:45 Reply

Basically you'll need to else if all of them. None of the if's are connected meaning the else won't check for the previous ones.


If ya have something to say, PM me. I have a lot of time to spare. Also never PM egg82.

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Walking animation fail 2013-01-24 12:53:25 Reply

public function playerMovement(event: Event):void {
			if (upKeyDown)
			{
				this.y -=  walkSpeed;
				this.gotoAndStop("playerWalk")
			}
			
			else if (downKeyDown)
			{
				this.y +=  walkSpeed;
				this.gotoAndStop("playerWalk");
			}
			
			if (leftKeyDown)
			{
				this.x -=  walkSpeed;
				this.scaleX = -1;
				this.gotoAndStop("playerWalk");
			}
			
			else if (rightKeyDown)
			{
				this.x +=  walkSpeed;
				this.scaleX = 1;
				this.gotoAndStop("playerWalk");
			}
			
			if(!upKeyDown && !downKeyDown && !leftKeyDown && !rightKeyDown)
			{
				this.gotoAndStop("playerIdle");
			}
		}

Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
gameObject
gameObject
  • Member since: Jan. 4, 2012
  • Offline.
Forum Stats
Member
Level 03
Game Developer
Response to Walking animation fail 2013-01-26 05:55:59 Reply

Dude, thank you.