[Stage3D] Feathersでシーン遷移! (1) ~ScreenNavigator~

Flash Player 11 から採用された Stage3D を学習するよ。 :bouzu:
Starling FrameworkFeathers でシーン遷移を試しちゃうんだからね。 :girl:

starling_feathers_screen31

:caution: 要 Flash Player 11.8 以上


This movie requires Flash Player 11.8.0

Main.as
package {

  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;

  import starling.core.Starling;

  [SWF(backgroundColor="#FFFFFF", width="360", height="640", frameRate="60")]

  public class Main extends Sprite {
    // プロパティ
    private var starling:Starling;

    // コンストラクタ
    public function Main() {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      init();
    }

    // メソッド
    private function init():void {
      mouseEnabled = false;
      mouseChildren = false;
      starling = new Starling(MainView, stage, null, null);
      starling.enableErrorChecking = true;
      starling.start();
    }

  }

}



import flash.geom.Rectangle;
import starling.core.Starling;
import starling.display.Sprite;
import starling.events.Event;
import starling.events.ResizeEvent;
import starling.animation.Transitions;

import feathers.controls.ScreenNavigator;
import feathers.controls.ScreenNavigatorItem;
import feathers.motion.transitions.ScreenSlidingStackTransitionManager;

import feathers.screens.Screen1;
import feathers.screens.Screen2;


internal class MainView extends Sprite {
  // プロパティ
  private var navigator:ScreenNavigator;
  private var transition:ScreenSlidingStackTransitionManager;
  private static var screen1:String = "screen1";
  private static var screen2:String = "screen2";

  // コンストラクタ
  public function MainView() {
    addEventListener(Event.ADDED_TO_STAGE, init);
    addEventListener(Event.REMOVED_FROM_STAGE, remove);
  }

  // メソッド
  private function init(evt:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, init);
    navigator = new ScreenNavigator();
    addChild(navigator);

    navigator.addScreen(screen1, new ScreenNavigatorItem(new Screen1(), {onNext: screen2}));
    navigator.addScreen(screen2, new ScreenNavigatorItem(new Screen2(), {onBack: screen1}));
    navigator.showScreen(screen1);

    transition = new ScreenSlidingStackTransitionManager(navigator);
    transition.duration = 0.4;
    transition.ease = Transitions.EASE_OUT;

  }
  private function remove(evt:Event):void {
    removeEventListener(Event.REMOVED_FROM_STAGE, remove);
  }
  override public function dispose():void {
    removeEventListener(Event.ADDED_TO_STAGE, init);
    removeEventListener(Event.REMOVED_FROM_STAGE, remove);
    super.dispose();
  }

}

Screen1.as (feathers.screens.Screen1.as)
package feathers.screens {

  import starling.display.Quad;
  import starling.events.Touch;
  import starling.events.TouchEvent;
  import starling.events.TouchPhase;

  import feathers.controls.Screen;
  import org.osflash.signals.Signal;
  import org.osflash.signals.ISignal;


  public class Screen1 extends Screen {
    // プロパティ
    protected var _onNext:Signal = new Signal(Screen1);

    // コンストラクタ
    public function Screen1() {
    }

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0x3366CC);
      addChild(back);
      addEventListener(TouchEvent.TOUCH, touch);
    }
    override protected function draw():void {
    }
    private function touch(evt:TouchEvent):void {
      var touch:Touch = evt.getTouch(this, TouchPhase.BEGAN);
      if (touch) {
        _onNext.dispatch(this);
      }
    }
    public function get onNext():ISignal {
      return _onNext;
    }

  }

}

Screen2.as (feathers.screens.Screen2.as)
package feathers.screens {

  import starling.display.Quad;
  import starling.events.Touch;
  import starling.events.TouchEvent;
  import starling.events.TouchPhase;

  import feathers.controls.Screen;
  import org.osflash.signals.Signal;
  import org.osflash.signals.ISignal;


  public class Screen2 extends Screen {
    // プロパティ
    protected var _onBack:Signal = new Signal(Screen2);

    // コンストラクタ
    public function Screen2() {
    }

    // メソッド
    override protected function initialize():void {
      var back:Quad = new Quad(360, 640, 0x66CCFF);
      addChild(back);
      addEventListener(TouchEvent.TOUCH, touch);
    }
    override protected function draw():void {
    }
    private function touch(evt:TouchEvent):void {
      var touch:Touch = evt.getTouch(this, TouchPhase.BEGAN);
      if (touch) {
        _onBack.dispatch(this);
      }
    }
    public function get onBack():ISignal {
      return _onBack;
    }

  }

}


[修正] (13/08/08 Thu 13:28)
ScreenNavigatorItemの引数で、クラスではなくインスタンスを渡す方式に変更。
[修正] (13/09/26 Thu 00:17)
Starling 1.4 にバージョンアップ。Feathers 1.1.1 にバージョンアップ。
[修正] (13/11/12 Tue 19:13)
Starling 1.4.1 にバージョンアップ。
[修正] (13/11/28 Thu 23:19)
Feathers 1.2.0 にバージョンアップ。
[修正] (14/06/25 Wed 15:16)
Starling 1.5 にバージョンアップ。Feathers 1.3.0 にバージョンアップ。
[修正] (14/06/25 Wed 17:10)
Starling 1.5.1 にバージョンアップ。
[修正] (14/12/15 Mon 16:45)
Starling 1.6 にバージョンアップ。Feathers 2.0.1 にバージョンアップ。