Player animation and moving


(Lars Nilsson) #1

Hello,

I cannot really figure out what I have done wrong here. Trying to get this character working.

Here is an example:

if (Input.check(Key.W) || Input.pressed(Key.UP)) {

y–; playerSheet.play(“runLeft”, true);

 if (collide("solid", x, y)) {
  y = y + 1;

} }

The sheet loops through 4 16x16 tiles, but he will just slide around. The animation itself works however if I change it to “Pressed” instead of “Check”, but he will move only about 1 pixel and then keep running in place.

Thanks for your help


(rostok) #2

Input.check() returns true only while key is pressed and till it is released. Input.pressed() however returns true only once, when the key was actually pressed. If you want to move the entity only while the key is being pressed and hold then do not reset the spritemap. Instead have just playerSheet.play("runLeft");.

Note that you can organize your input like this:

Input.define("up", Key.W, Key.UP);

and later use

Input.check("up");

which is much more convienient.


(Lars Nilsson) #3

It works, thank you!