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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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