Jump to content

Animating Enemy


Recommended Posts



So i have been able to add enemy to my game via spritesheet.


I can create the animations successfully and set the velocity in the x direction that I want.


What I want to do is be able to update if his going right or left.

    if (baddie.x < 0) {                baddie.animations.play('left');    }    else if (baddie.x > 0) {                baddie.animations.play('right');    }    

So clearly this doesn't work because the X value is always a positive value. Is there a way to check if the value of X is decreasing to play animation "Left" or increasin to play animation "Right"?


Or other ways to solve this issue would be great.


Basicly is an enemy that has the Arcade Physics, bounce, and collides with world boundaries. 


I would almost think i could use the following:

baddie.facing = Phaser.left//in the update function in an "if" statement 

However i am not sure how to properly put it together.

Thanks AR

Link to comment
Share on other sites

Ok thanks for anyone that attempted to help :)


I decided to run the debug on my baddie and stared at the values it returned! and then i noticed only one went positive to negative! doh!


The Velocity not the location on the map. 



 if (baddie.body.velocity.x > 0) {                baddie.animations.play('right');    }    else {                baddie.animations.play('left');    }

Ok so now to create a collision between the Baddie and The Player to kill Player Left or Right


Or if baddie top to Player bottom kill Baddie




Start State

Pause State

End State

Re-Design Level

Write about my experience.


One feature a day!

Link to comment
Share on other sites


  • Recently Browsing   0 members

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