[Stage3D] Starlingを試すのだ! (5) ~MovieClip, Texture, TextureAtlas~

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

starling35

MovieClipクラスTextureクラスTextureAtlasクラスを使ってみちゃうよ。 :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="200", 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.enableErrorChecking = true;
      starling.start();
    }

  }

}



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


internal class MainView extends Sprite {
  [Embed(source="assets/piyo.png")]
  private var PiyoTexture:Class;
  [Embed(source="assets/piyo.xml", mimeType="application/octet-stream")]
  private var PiyoAtlas:Class;
  // プロパティ
  private var texture:Texture;
  private var atlas:TextureAtlas;
  private var piyo:MovieClip;

  // コンストラクタ
  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);
    texture = Texture.fromBitmap(new PiyoTexture());
    atlas = new TextureAtlas(texture, XML(new PiyoAtlas()));

    piyo = new MovieClip(atlas.getTextures(), 60);
    piyo.currentFrame = Math.random()*60;
    piyo.pivotX = 26;
    piyo.pivotY = 59;
    piyo.x = 300;
    piyo.y = 175;
    addChild(piyo);

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

}

Texture, TextureAtlasデータは「TexturePacker」というツールで作成。 :doki:
データ形式は「Sparrow」でパブリッシュ。
:check: 「TexturePacker - Sprite sheet maker, image packer and optimizer | TexturePacker | Sprite sheet creation and image optimization

piyo.png

starling35_piyo

piyo.xml
<?xml version="1.0" encoding="UTF-8"?>
<!- Created with TexturePacker http://texturepacker.com->
<!- $TexturePacker:SmartUpdate:******************************$ ->
<TextureAtlas imagePath="piyo.png">
<SubTexture name="piyo0001" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0002" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0003" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0004" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0005" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0006" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0007" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0008" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0009" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0010" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0011" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0012" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0013" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0014" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0015" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0016" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0017" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0018" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0019" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0020" x="110" y="203" width="52" height="65"/>
<SubTexture name="piyo0021" x="56" y="203" width="52" height="65"/>
<SubTexture name="piyo0022" x="2" y="203" width="52" height="65"/>
<SubTexture name="piyo0023" x="164" y="136" width="52" height="65"/>
<SubTexture name="piyo0024" x="110" y="136" width="52" height="65"/>
<SubTexture name="piyo0025" x="56" y="136" width="52" height="65"/>
<SubTexture name="piyo0026" x="110" y="136" width="52" height="65"/>
<SubTexture name="piyo0027" x="164" y="136" width="52" height="65"/>
<SubTexture name="piyo0028" x="2" y="203" width="52" height="65"/>
<SubTexture name="piyo0029" x="56" y="203" width="52" height="65"/>
<SubTexture name="piyo0030" x="110" y="203" width="52" height="65"/>
<SubTexture name="piyo0031" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0032" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0033" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0034" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0035" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0036" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0037" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0038" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0039" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0040" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0041" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0042" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0043" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0044" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0045" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0046" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0047" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0048" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0049" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0050" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0051" x="164" y="203" width="52" height="65"/>
<SubTexture name="piyo0052" x="2" y="136" width="52" height="65"/>
<SubTexture name="piyo0053" x="164" y="69" width="52" height="65"/>
<SubTexture name="piyo0054" x="110" y="69" width="52" height="65"/>
<SubTexture name="piyo0055" x="56" y="69" width="52" height="65"/>
<SubTexture name="piyo0056" x="2" y="69" width="52" height="65"/>
<SubTexture name="piyo0057" x="164" y="2" width="52" height="65"/>
<SubTexture name="piyo0058" x="110" y="2" width="52" height="65"/>
<SubTexture name="piyo0059" x="56" y="2" width="52" height="65"/>
<SubTexture name="piyo0060" x="2" y="2" width="52" height="65"/>
</TextureAtlas>


[修正] (12/01/21 Sat 19:20)
ひよこちゃんの動きを30fpsから60fpsに変更。
[修正] (12/05/02 Wed 02:09)
Starling 1.1 にバージョンアップ。
[修正] (12/08/28 Tue 22:25)
Starling 1.2 にバージョンアップ。
[修正] (13/01/17 Thu 11:37)
Starling 1.3 にバージョンアップ。
[修正] (13/09/26 Thu 00:04)
Starling 1.4 にバージョンアップ。
[修正] (13/11/12 Tue 18:23)
Starling 1.4.1 にバージョンアップ。
[修正] (14/06/25 Wed 14:55)
Starling 1.5 にバージョンアップ。
[修正] (14/06/25 Wed 17:00)
Starling 1.5.1 にバージョンアップ。
[修正] (14/12/14 Sun 20:20)
Starling 1.6 にバージョンアップ。