Sign in to follow this  
swemaniac

How do I rotate (tween) a sprite in a specific direction?

Recommended Posts

Hi,

 

First off thanks to Phaser. It's awesome.

 

How do I tween a sprite's angle from say 180 degrees to 360 degrees in a clockwise direction? If i just do tween.to({ angle: 360}) the sprite will rotate counter clockwise. In Phaser angles that would be from 180 to -90. Obviously it's because the tween will go down from 180 to -90, but I want it to to go upwards and wrap around i.e. 180, -179, -178 etc. Make any sense? :)

 

Thanks

Share this post


Link to post
Share on other sites

Tweens usually aren't very smart about how they work - essentially all a tweener does is gradually change one number to another, so angles are often problematic. You'd be better off adding something to your update function which increments the sprite.angle by a small amount each frame:

function update() {  if (sprite.isRotating) {    sprite.angle += 1;  }}

Then all you have to do is set sprite.isRotating to true and it'll start turning steadily. Be aware that this is a naive implementation that doesn't account for framerate differences; it'll turn slower with lower framerates. There are easy ways to tackle that if needs be.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.