[Stage3D] Starlingでブラインド遷移 (1) ~clipRect~

Flash Player 11 から採用された Stage3D を学習するよ。 :bouzu:
Starling Framework を試しちゃうんだからね。 :girl:

starling_blind1

clipRectプロパティを用いて、ブラインド遷移を試してみるよ。 :boy:

: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="600", height="480", 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 {
      starling = new Starling(MainView, stage, null, null);
      starling.showStatsAt("right", "top", 1);
      starling.enableErrorChecking = true;
      starling.start();
    }

  }

}



import starling.core.Starling;
import starling.display.Sprite;
import starling.display.Image;
import starling.textures.Texture;
import starling.events.Event;

import flash.geom.Rectangle;
import a24.tween.Tween24;
import a24.tween.events.Tween24Event;


internal class MainView extends Sprite {
  [Embed(source="assets/photo/photo1.jpg")]
  private var Photo1:Class;
  [Embed(source="assets/photo/photo2.jpg")]
  private var Photo2:Class;
  [Embed(source="assets/photo/photo3.jpg")]
  private var Photo3:Class;
  [Embed(source="assets/photo/photo4.jpg")]
  private var Photo4:Class;
  // プロパティ
  private var container:Sprite;
  private var contents:Array;
  private var slides:Array;
  private var textures:Array;
  private static var rect:Rectangle;
  private static var max:uint = 4;
  private static var lines:uint = 14;
  private var atween:Tween24;
  private var photoId:uint = 0;

  // コンストラクタ
  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);
    var texture1:Texture = Texture.fromBitmap(new Photo1());
    var texture2:Texture = Texture.fromBitmap(new Photo2());
    var texture3:Texture = Texture.fromBitmap(new Photo3());
    var texture4:Texture = Texture.fromBitmap(new Photo4());

    textures = [texture1, texture2, texture3, texture4];
    rect = new Rectangle(0, 0, 40, 420);
    container = new Sprite();
    addChild(container);

    container.x = 20;
    container.y = 35;
    contents = [];
    slides = [];
    for (var n:uint = 0; n < max; n++) {
      var content:Sprite = new Sprite();
      container.addChild(content);

      contents[n] = content;
      slides[n] = [];
      for (var t:uint = 0; t < lines; t++) {
        var slide:Sprite = new Sprite();
        content.addChild(slide);

        slide.pivotX = 20;
        slide.x = 20 + 40*t;
        slide.clipRect = rect;
        slide.scaleX = 0;
        slides[n][t] = slide;
        var image:Image = new Image(textures[n]);
        slide.addChild(image);

        image.pivotX = 40*t;
      }
    }
    start();
  }
  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();
  }
  private function start():void {
    var content:Sprite = contents[photoId];
    container.addChild(content);

    var tweens:Array = [];
    for (var t:uint = 0; t < lines; t++) {
      var slide:Sprite = slides[photoId][t];
      slide.scaleX = 0;
      tweens[t] = Tween24.tween(slide, 0.6, Tween24.ease.SineOut).scaleX(1).delay(0.2*t);
    }
    atween = Tween24.parallel(tweens);
    atween.addEventListener(Tween24Event.COMPLETE, complete, false, 0, true);
    atween.play();

  }
  private function complete(evt:Tween24Event):void {
    atween.removeEventListener(Tween24Event.COMPLETE, complete);
    photoId = (photoId + 1)%max;
    start();
  }

}


[修正] (14/06/25 Wed 15:27)
Starling 1.5 にバージョンアップ。
[修正] (14/06/25 Wed 17:16)
Starling 1.5.1 にバージョンアップ。
[修正] (14/10/08 Wed 14:41)
Tween24 2.1 にバージョンアップ。
[修正] (14/12/14 Sun 20:51)
Starling 1.6 にバージョンアップ。