views:

232

answers:

3

Sprite.rotation+=10; Sprite.rotation*=0.97;

because in as3 the system goes from 180 to -180 I don't know how to apply a drag to a constantly rotating object if it moves either direction. Do I have to convert to radians somehow and then do something? I am pretty bad with math.

A: 

In AS3 you can continually increase or decrease rotation and it will keep rotating in that direction - it doesn't go from 180 to -180 as you state in your question - your above code will in fact work...

Reuben
oops - my mistake
Reuben
lol, that's pretty funny
Daniel Hanly
A: 

It actually does goes from 180 to -180 (contrary to what Reuben says), but higher/lower values get automatically corrected to that range (i.e. 181 is converted to -179)... one way to work with this is to use an auxiliary variable for your math (animation or whatever) and then assign it to the rotation, say:

myVar+=10;
myVar*=.97;
clip.rotation=myVar;
Cay
this is the answer I was looking for, thanks alot
Jeffrey
+1  A: 

I'm not sure "drag" makes sense with the code you've posted. What you've shown would slowly wind the object back to 0 rotation.

If you want a drag/acceleration effect, create a separate variable with your acceleration factor, which you apply every frame. Then, you can apply a factor to that variable to slow rotation down/speed it up.

Something like:

private var _rotationAcceleration:Number = 0;
private var _dragFactor:Number = 0.97;
private var _clip:Sprite;

private function startSpin():void {
    _rotationAcceleration = 10.0;
}
private function enterFrameListener(event:Event):void {
    _clip.rotation += _rotationAcceleration;
    _rotationAcceleration *= _dragFactor;
}
Cory Petosky