Jump to content

Tween Rotation / Shortest Distance?


Recommended Posts


What you want to do is to rotate your sprite to 0 or Math.PI * 2 (which is whole turn, 360 degrees), depending on which one is closest to the current rotation.

First you should convert your current rotation to value between 0 - Math.PI * 2. You can do that by using modulus operator

sprite.rotation = sprite.rotation % (Math.PI * 2);

Then just check if the rotation is more than Math.PI (which is half turn, 180 degrees). If it is, rotate to Math.PI * 2, if not then rotate to 0.

sprite.rotation = sprite.rotation % (Math.PI * 2);

var target = 0;
if (sprite.rotation > Math.PI) target = Math.PI * 2;

game.Tween.add(sprite, {
    rotation: target
}, 500).start();


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.

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.


  • Recently Browsing   0 members

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