[Stage3D] Starlingでカラー効果 (2) ~Imageのcolorプロパティ~

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

starling_color2

Imageクラスcolorプロパティを使ってみちゃうよ。 :boy:

:caution: 要 Flash Player 11.8 以上

Imageの黒い部分は、colorプロパティでは着色できないので、注意が必要だよ! :bear:

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="450", 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.Image;
import starling.display.Quad;
import starling.events.Event;
import starling.textures.Texture;
import starling.filters.ColorMatrixFilter;


internal class MainView extends Sprite {
  [Embed(source="assets/logo_black.png")]
  private var LogoBlackTexture:Class;
  [Embed(source="assets/logo_white.png")]
  private var LogoWhiteTexture:Class;
  // プロパティ

  // コンストラクタ
  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 blacktexture:Texture = Texture.fromBitmap(new LogoBlackTexture());
    var whitetexture:Texture = Texture.fromBitmap(new LogoWhiteTexture());


    //黒ベースのロゴImage
    var blacklogo:Image = createLogo(blacktexture);
    blacklogo.x = 170;
    blacklogo.y = 160;

    var blacklogo1:Image = createLogo(blacktexture);
    blacklogo1.x = 170;
    blacklogo1.y = 250;
    blacklogo1.color = 0xFF3366;

    var blacklogo2:Image = createLogo(blacktexture);
    blacklogo2.x = 170;
    blacklogo2.y = 320;
    blacklogo2.color = 0x66CC00;

    var blacklogo3:Image = createLogo(blacktexture);
    blacklogo3.x = 170;
    blacklogo3.y = 390;
    blacklogo3.color = 0x00CCFF;

    //白ベースのロゴImage
    var whitelogo:Image = createLogo(whitetexture);
    whitelogo.x = 430;
    whitelogo.y = 160;

    var whitelogo1:Image = createLogo(whitetexture);
    whitelogo1.x = 430;
    whitelogo1.y = 250;
    whitelogo1.color = 0xFF3366;

    var whitelogo2:Image = createLogo(whitetexture);
    whitelogo2.x = 430;
    whitelogo2.y = 320;
    whitelogo2.color = 0x66CC00;

    var whitelogo3:Image = createLogo(whitetexture);
    whitelogo3.x = 430;
    whitelogo3.y = 390;
    whitelogo3.color = 0x00CCFF;
  }
  private function createLogo(texture:Texture):Image {
    var logo:Image = new Image(texture);
    addChild(logo);
    logo.pivotX = 114;
    logo.pivotY = 29;
    return logo;
  }
  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();
  }

}