Don't Escape
I'm a werewolf and it's a full moon. I have to find a way to prevent myself from escaping.
3.68 / 5.00 26,672 ViewsRagnarok Online Jigsaw
Did you play Ragnarok Online? Do you like that game?
3.57 / 5.00 12,351 ViewsGood 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
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"
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...
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.
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