forked from: Tweenerの挙動?
forked from Tweenerの挙動? (diff: 10)
しかくクリックでTweener動きます rotation181以上で同じ値でTweenさせると、なぜぐるっと一回転するのか? 回らないのを想像してたんだが・・・いまさら? なんかいい回避方法ないですか?って概出? おとなしく違うライブラリ使えってことですね。
ActionScript3 source code
/**
* Copyright keno42 ( http://wonderfl.net/user/keno42 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ov8B
*/
// forked from minon's Tweenerの挙動?
//しかくクリックでTweener動きます
//rotation181以上で同じ値でTweenさせると、なぜぐるっと一回転するのか?
//回らないのを想像してたんだが・・・いまさら?
//なんかいい回避方法ないですか?って概出?
//おとなしく違うライブラリ使えってことですね。
package {
import caurina.transitions.Tweener;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var _box:Sprite;
private var _txt:TextField;
public function FlashTest() {
// write as3 code here..
_box = new Sprite();
_box.graphics.beginFill( 0xFF0000, 1 );
_box.graphics.drawRect( -50, -50, 100, 100 );
_box.graphics.endFill();
_box.x = _box.y = 200;
this.addChild( _box );
_txt = new TextField();
_txt.border = true;
_txt.text = "220";
_txt.type = TextFieldType.INPUT;
this.addChild( _txt );
_box.addEventListener( MouseEvent.CLICK, function():void {
// 移動距離が最短になる角度を計算
var target:Number = Number(_txt.text);
// 角度差を-360~360度の間に納める
target = (target - _box.rotation)%360 + _box.rotation;
// 180度以上の移動ならマイナス側にまわしたほうが近い
if( (target - _box.rotation) > 180 ) target -= 360;
// -180度以下の移動ならプラス側にまわしたほうが近い
else if( (target - _box.rotation) < -180 ) target += 360;
Tweener.addTween( _box, { rotation:target, time:0.6, transition:"easeOutQuad" } );
} );
}
}
}