Sign in to follow this  
geleto

How do I tween the rotation

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;
    }
});

Share this post


Link to post
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.

Share this post


Link to post
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)
    }
)...

 

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.