Jump to content

Certain Frame Animations with JSON Array


Heppell08
 Share

Recommended Posts

Pretty much the title. I have a 5 frame character and i want to use 3 frames for walking, 1 frame for jumping and another for dying. 

I also need to know how to reverse the image so left faces left and right faces right. I almost posted on how to use JSON but figured it out. 

Just need help with reversing an image and using certain frames of an image.

Thanks in advance

Link to comment
Share on other sites

To flip the sprites, reverse the sign of the scale property:

sprite.scale.x *= -1; //flip horizontally

sprite.scale.y *= -1; //flip vertically

Remember to set the anchor properly, generally:

sprite.anchor.setTo(0.5, 0.5); //so the texture of the sprite is centered

 

So if i have for example my character walking to the left, i would have it as

function update() {         if(cursors.left.isDown)	{		player.body.velocity.x = -150;                sprite.scale.x *= -1;		player.animations.play('left');	}}

Like that to use it?

 

Also is there a specific way to use a specific frame at a specific time 

 

EG: player dies, play death animation but from JSON array instead. Dont know if its possible but worth asking i suppose if someone knows. 

 

Thanks for the scale tip :)

Link to comment
Share on other sites

If you use it like that, you sprite will constantly flip while the left key is pressed.

 

Because every update method "sprite.scale.x *= -1;" will change the direction again and again - so you only do it  when you press the key first.

 

if (sprite.scale.x > 0) { sprite.scale.x *= -1;}

 

And if you press the right-curosr-key, you have to flip it back to be a positive number.

 

If you do not scale your sprite, you could skip the check and just set it to "-1" for left, and "1" for walking right. (instead of changing the sign only.)

 

Also you might not want to have an animation named "left" because you can use the same walk animation for left and right (because you flip the sprite).

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...