Jump to content

Got some beginner questions


DudeshootMankill
 Share

Recommended Posts

Hey there, i'm new to phaser and relatively new to coding in general. I'm loving phaser, its got loads of documentation and a whole lot of tutorials. I'm currently working on a sidescroller of my own and now i'm kind of stuck. I hope some helpful forum member's got time to answer some perhaps very obvious questions.

 

First off:

 

if (cursors.left.isDown)

{player.animations.play('walk', 7);

player.body.velocity.x = -130;

player.scale.x = -1;

} else if (cursors.right.isDown) {

player.scale.x = 1;

player.body.velocity.x = 130;

player.animations.play('walk', 7);

}

 

This is my code for walking across the screen. I need to work out how i can, after left or right has been released ”default” to another animation. One called 'idle'. If i use else{layer.animations.play('idle', 7); it does the exact intended effect but it screws everything else up, i imagine that'd be like the idle animation being invoked continuuously. The problem here is that phaser plays all 5 frames of my walk animation currently, even if i've just pressed left or right for 0.01 second.

 

I'd also like it if someone could hint at how i'd play an animation for when my character turns from left to right and vice versa.

 

Secondly:

 

if (cursors.up.isDown && player.body.onFloor())

{player.body.velocity.y = -190;}

 

This is my code for jump. I'd like to know if its possible to play a short animation when jumping, stop at a frame and then play out the rest of that animation when landing. I imagine if i just use if(player.body.onFloor) → play animation, i'd make a mess out of things aswell. Perhaps an animation for when not touching ground and y movement?

 

Thanks for any hints you might provide me.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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