[AS3.0] Tweenerとスプライン曲線

AS3.0 定番の Tweener を試してみるよ。 :boy:
スクリプトでアニメーション制御ができる、凄いものらしい。

特殊プロパティ「_spline」を試してみるよ。 :bouzu:

:caution: 要 Flash Player 9 以上

ただし、snapfit.lib.tweener.SplineModifiers.as が必要だよ。
参考資料「[as]Tween on Spline Curve [NUTSU]

This movie requires Flash Player 9.0.0
Main.as
package {

  import flash.display.Sprite;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.geom.Point;

  import caurina.transitions.Tweener;
  import snapfit.lib.tweener.SplineModifiers;

  import jp.nya.project.character.FrogA;
  import jp.nya.project.controls.Btn;


  [SWF(backgroundColor="#FFFFFF", width="600", height="600", frameRate="30")]

  public class Main extends Sprite {
    // プロパティ
    private var frog:FrogA;
    private var playBtn:Btn;
    private var canvas:Sprite;
    private static var cx:uint = 300;
    private static var cy:uint = 280;
    private var aPoint:Sprite;
    private var p1Point:Sprite;
    private var p2Point:Sprite;
    private var bPoint:Sprite;

    // コンストラクタ
    public function Main() {
      CurveModifiers.init();
      init();
    }

    // メソッド
    private function init():void {
      canvas = new Sprite();
      addChild(canvas);
      aPoint = new Sprite();
      addChild(aPoint);
      p1Point = new Sprite();
      addChild(p1Point);
      p2Point = new Sprite();
      addChild(p2Point);
      bPoint = new Sprite();
      addChild(bPoint);
      draw(null);
      frog = new FrogA();
      addChild(frog);
      frog.x = cx;
      frog.y = cy;
      playBtn = new Btn();
      addChild(playBtn);
      playBtn.x = 300;
      playBtn.y = 580;
      playBtn.init({label: "play"});
      playBtn.addEventListener(MouseEvent.CLICK, play, false, 0, true);
    }
    private function play(evt:MouseEvent):void {
      if (!Tweener.isTweening(frog)) {
        frog.x = aPoint.x;
        frog.y = aPoint.y;
        Tweener.addTween(frog, {x: bPoint.x, y: bPoint.y, _spline: [{x: p1Point.x, y: p1Point.y}, {x: p2Point.x, y: p2Point.y}], time: 3, transition: "linear", onComplete: complete});
      } else {
        Tweener.resumeTweens(frog);
      }
      playBtn.clicked = true;
      playBtn.removeEventListener(MouseEvent.CLICK, play);
    }
    private function complete():void {
      frog.x = cx;
      frog.y = cy;
      playBtn.clicked = false;
      playBtn.addEventListener(MouseEvent.CLICK, play, false, 0, true);
    }

  }

}

Xcode + Flex 2 SDK + Terminal
$ mxmlc -library-path+=components/FrogA.swc,components/Btn.swc Main.as
とする。

:caution: 注意点
:banana: [AS3.0] スプライン曲線 のスプライン曲線とは若干異なる。
参考資料「l00oo.oo00l blog » Catmull-Rom スプライン曲線