Jump to content

Help managing sprite orientation


kcurtin
 Share

Recommended Posts

I am using some art of a player character for a top down game I am making - the art is here: http://opengameart.org/content/top-down-mage-animations

 

The sprite is orientated so that the mage's face / front is facing upward (north).

I'm having some issue with rotation, with both mouse movement and keyboard movement. For example, I have this "hack" that adds additional radians to a calculated angle in order to get the mage's "front" to face the pointer instead of the right shoulder: 

 
this.rotation = this.game.physics.arcade.angleToPointer(this, pointer) + 1.57079633;
 
Is there an easier way to handle this? I'm running in to the same issue attempting to use angular velocity for keyboard movements:
 
this.game.physics.arcade.velocityFromAngle(this.angle, 300, this.body.velocity);
 
The goal is to get wasd to rotate and move the character similar to the example here: http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=angular+velocity.js&t=angular%20velocity)
 
What is the best way to get the front of the sprite to face the direction the sprite is moving? I will also be having objects that "shoot" out from the front of the sprite, which will have to be based on it's rotation so I'd rather calculate the offset a single time instead of all over the place... Let me know if this makes sense. Thank you!
 
 

 

Link to comment
Share on other sites

The surefire way is to ensure your sprites all face to the right by default, as this is where the rotation's zero point is. Otherwise the way you're doing it (by adding 90 degrees in radians to the value) is the typical solution. You could maybe write a small function called 'fixRotation' which you wrap around any rotation value, and will add the 90 degree offset to it if you don't want to fill your code with 1.57079633.

function fixRotation(rotation) {  return rotation + 1.57079633;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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