[Stage3D] Genome2Dを試すのだ! (2) ~GSprite, GTexture~

Flash Player 11 から採用された Stage3D を学習するよ。 :bouzu:
Genome2D を試してみちゃうよ。 :girl:

genome2d32

GSpriteクラスGTextureクラスを使ってみるよ。 :boy:

:caution: 要 Flash Player 11.0 以上

This movie requires Flash Player 11.0.0

Main.as
package {

  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;
  import flash.events.Event;
  import flash.geom.Rectangle;

  import com.genome2d.core.Genome2D;
  import com.genome2d.core.GNode;
  import com.genome2d.context.GContextConfig;
  import com.genome2d.components.GCamera;
  import com.genome2d.components.renderables.GSprite;
  import com.genome2d.textures.GTexture;
  import com.genome2d.textures.factories.GTextureFactory;


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

  public class Main extends Sprite {
    [Embed(source="assets/background.png")]
    private var Background:Class;
    // プロパティ
    private var scene:Genome2D;
    private var container:GNode;
    private var camera:GCamera;

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

    // メソッド
    private function init():void {
      scene = Genome2D.getInstance();
      scene.onInitialized.addOnce(initialized);
      scene.onFailed.addOnce(failed);
      scene.autoResize = false;
      var config:GContextConfig = new GContextConfig();
      config.renderMode = GContextConfig.AUTO;
      config.viewRect = new Rectangle(0, 0, 600, 400);
      config.separateNoAlphaShaders = true;

      scene.init(stage, config);
    }
    private function initialized():void {
      container = new GNode("container");
      container.transform.x = stage.stageWidth/2;
      container.transform.y = stage.stageHeight/2;

      scene.root.addChild(container);
      camera = GCamera(container.addComponent(GCamera));
      var back:GNode = new GNode("back");
      back.transform.setScale(600/400, 400/300);
      var sprite:GSprite = GSprite(back.addComponent(GSprite));
      var texture:GTexture = GTextureFactory.createFromAsset("background", Background, false);
      sprite.setTexture(texture);

      container.addChild(back);
    }
    private function failed():void {
      trace("failed");
    }

  }

}