1
votes

I have a little issue, I'm rotating an object. I want rounded values for rotating the object for efficiency.

TweenLite.to(this, 1, { rotation:rotation+100 });
//Output rotation values
//83.02559999999998, 85.55999999999999, 88.02839999999999, 90.1404, 92.16, 93.8496

so I tried this

TweenLite.to(this, 1, { rotation:rotation+100, onUpdate:function()
{
    rotation = Math.round(rotation);
}
});

But to no avail. Any ideas ?

3
Are rounded rotation values really more efficient? - Mark Knol
@MarkKnol In general programming, floating points demands more processing than integers. Especially undue floating points causes processor to do extra work than normal. Of course limited use is unnoticeable. Extreme example of floating point which drives the CPU mad is PI calculation. - Muhammad
I think this only gives extra overhead instead of optimization, since you calculations did not change, you only alter the output. Since there is missing info why you want to use this, I think you should not optimize in this way. By the way, TweenMax has a build-in feature for faster rendering of rotation, using the TranformMatrixPlugin, see greensock.com/tweening-tips - Mark Knol

3 Answers

2
votes

You can try to use proxy object, such as

var obj:Object = {};
obj.rotation = this.rotation;
TweenLite.to(obj, 1, { rotation:rotation+100, onUpdate:function()
{
    if (this.rotation != Math.round(obj.rotation))
        this.rotation = Math.round(obj.rotation);
}
});
0
votes

How about

TweenLite.to(this, 1, { rotation:Math.round(rotation+100) });
0
votes

If rendering is a problem; TweenMax has a build-in feature for faster rendering of rotation, using the TransformMatrixPlugin, see http://greensock.com/tweening-tips