Frozen Sprites Problem


(Oli) #1

Im sry to ask here again but I have found my self to run into some other problems. I made my guy running and assign some spritemap to its movements (2 different spritemaps: left run cycle + idle, right run cycle + jump)

So everytimes I press the left or right imput it changes the graphic of the character and call the animation at the same time but my problem is that it freeze on the first frame everytime I do so. Does anyone have any idea whats going on?

public override function update():void
{ // Checking player input. var hInput:int = 0;

		if (Input.check(Key.LEFT)) 
		{
			(hInput -= 1) && (graphic = sprKoreanDudeJUMP) && (sprKoreanDudeJUMP.play("runleft", true));
		}
		else
		{
			(graphic = sprKoreanDude) && (sprKoreanDude.play("stand", true));
		}
		
		if (Input.check(Key.RIGHT))
		{
			(hInput += 1) && (graphic = sprKoreanDude) && (sprKoreanDude.play("run", true));
		}
		else
		{
			sprKoreanDude.play("stand", true);
		}
			
		
		if (Input.check(Key.SPACE)) 
		{
		(jump()) && (graphic = sprKoreanDudeJUMP) &&(sprKoreanDudeJUMP.play("jump", true));
		}
		else 
		{
	    a.y = GRAVITY;
		v.y += a.y;
		}			

I find the people on this forum very nice and I greatly apreciate the help


(Justin Wolf) #2

When you’re playing your sprites, you’re setting the second parameter of the play function to “true”. Setting this parameter to true will always play your sprite from the first frame no matter if that current animation is already playing or not.

So in your case, the game is checking if a key is down every frame, and if so, it should play the appropriate sprite. But since you have the second parameter set to true, it plays the appropriate sprite but always resets to the first frame.

Go through all of your sprKoreanDude.play(); functions and remove the second true parameter.


(Oli) #3

thx man i apreciate your help


(Jacob Albano) #4

Your problem is that you reset the animation to “stand” every frame, because it’s set in the else clause of both of your input checks.

Try something like this:

var hInput:int = 0;

if (Input.check(Key.LEFT))
{
    hInput = -1;
}

if (Input.check(Key.RIGHT)) 
{
    hInput = 1;
}

if (hInput == 0)
{
    // play stand animation
}

I’m not sure why you’re using && all over the place instead of using separate statements separated by semicolons. It’s also probably not a good idea to be setting the graphic multiple times per frame. Neither of those issues are your problem, however.


(Oli) #5

thx, yea your right im just starting with programing so im not use to the conventions yet :smile:


(Jacob Albano) #6

I thought that might be the case. :wink: No worries! Everyone starts somewhere, and we’re here for you if you need anything else.