Jump to content

Animation and collisions


letmaelk
 Share

Recommended Posts

Hi.

I am trying to make the animations for my player, by doing so i have make a texture atlas.

Once the player spawns, he spawns a little in the air ( so the update starts "jump" animation ), once he reaches ground ( when player.body.blocked.down is true) the animation updates to "standing"

Once he is ON the ground, my problem occurs, because the jump sprite height is 30 pixels, and the STANDING sprite height is 31 pixels.

It CONSTANTLY changes between those animations, and i cant figure out a solution to this :-O



Heres a little code:

This is the sprite for jump

{
	"filename": "white-body1",
	"frame": {"x":0,"y":0,"w":35,"h":30},
	"rotated": false,
	"trimmed": false,
	"spriteSourceSize": {"x":0,"y":0,"w":35,"h":30},
	"sourceSize": {"w":35,"h":30}
},

And this is the sprite for standing:

{
	"filename": "white-body2",
	"frame": {"x":37,"y":0,"w":30,"h":31},
	"rotated": false,
	"trimmed": false,
	"spriteSourceSize": {"x":0,"y":0,"w":30,"h":31},
	"sourceSize": {"w":30,"h":31}
},



This is the update code:

			if(keyboard.left.isDown){
				
				player.body.velocity.x = -250;
				
			} else if(keyboard.right.isDown){
				
				player.body.velocity.x = 250;
				
			} else {

				player.animations.play('standing');
				
			}			

			if(!player.body.blocked.down) {
				
				player.animations.play("jump");
				
			}



 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...