Jump to content

How do I tween the rotation


geleto
 Share

Recommended Posts

... I've found a solution:

game.RotatableEntity = me.Entity.extend({
    init: function(x, y, sprite) {
        this._super(me.Entity, "init", [x, y, {
            width: sprite.width,
            height: sprite.height
        }]);
        this.renderable = sprite;
        this.currentAngle = 0;
        this.prevAngle = 0;
    },
    update: function() {
        this.renderable.currentTransform.rotate(this.currentAngle-this.prevAngle);
        this.prevAngle = this.currentAngle;
        return true;
    }
});
Link to comment
Share on other sites

that's exactly what I do as well in one of my project, but in my case I pass an increment delta angle so that the object keep spinning (I just need then to negate the value if I want to reverse the rotation)

If you want to tween it, then you can either change the delta angle value passed to rotate, or change the target angle in your case.

Link to comment
Share on other sites

I don't get the delta in the callback. It seems to pass the current tween value in the 0-1 range except that for InOut easing, when reaching 1, instead of tweening back to 0 - it starts incrementing from 0.

Here's a fiddle: https://jsfiddle.net/o8dpLngw/1/

...onUpdate(
    function(val){
        console.log( logo.currentAngle, val*maxAngle, (1-val)*maxAngle)
    }
)...

 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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