Bitmapのdrawを使用した方法をメモ


自分が思ったなるほど・・と思った点


■ENTER_FRAME内でのdraw


BitmapDataを作成してそこにステージ自体・・[this]をdrawさせるとステージに表示されているオブジェクトが描画される。

またENTER_FRAMEでループさせているのでオブジェクトを移動させている間もdrawされるのでちょいと幻想的な描画ができる。


■scrollを使用するとdrawで描画されたものが移動する


scrollを調べてみたところ、「x」および「y」パラメーターは「int型」でx軸とy軸のスクロール量をピクセルで指定する。

とのことでした。


package {
import caurina.transitions.*;
import flash.filters.BlurFilter;
//
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.events.*;
import flash.display.*;

/**
* ...
* @author $(DefaultUser)
*/
public class BitMapTest2 extends MovieClip{
//
public var start_btn:MovieClip;
//
//Bitmap関連
private var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x000000);
private var bm:Bitmap = new Bitmap(bmd);
private var bf:BlurFilter = new BlurFilter(5, 5, 3);   //ぼかし量を設定
//オブジェクト
private var obj1:cr=new cr();
private var obj2:cr2=new cr2();
private var obj3:cr3=new cr3();
private var obj4:cr4=new cr4();
//---------------------
//コンストラクタ
//---------------------
public function BitMapTest2() {
//
start_btn.addEventListener(MouseEvent.CLICK, doCLick);
start_btn.buttonMode = true;
}

private function doCLick(e:MouseEvent):void {
addChild(bm);
addChild(obj1);
addChild(obj2);
addChild(obj3);
addChild(obj4);
//
obj1.x = stage.stageWidth / 2;
obj1.y = stage.stageHeight / 2;
//
obj2.x = stage.stageWidth / 2;
obj2.y = stage.stageHeight / 2;
//
obj3.x = stage.stageWidth / 2;
obj3.y = stage.stageHeight / 2;
//
obj4.x = stage.stageWidth / 2;
obj4.y = stage.stageHeight / 2;
//

//
addEventListener(Event.ENTER_FRAME, LoopAction);
}

private function LoopAction(e:Event):void {
bmd.draw(this);                         //ステージを描画
bmd.scroll(0,1);                         //y軸に一ピクセルスクロール
bmd.applyFilter(bmd, bmd.rect, new Point(0, 0), bf);   
//
Tweener.addTween(obj1, {
x:mouseX,
y:mouseY,
rotation:Math.random() * 100,
transition:"easeOutExpo",
time:1
} );
Tweener.addTween(obj2, {
x:450-mouseX,
y:mouseY,
rotation:Math.random() * 100,
transition:"easeOutExpo",
time:1
} );
Tweener.addTween(obj3, {
x:mouseY,
y:450-mouseX,
rotation:Math.random() * 100,
transition:"easeOutExpo",
time:1
} );
Tweener.addTween(obj4, {
x:mouseY,
y:mouseX,
rotation:Math.random() * 100,
transition:"easeOutExpo",
time:1
} );
}

}

}


applyFilterを設定しないとオブジェクトがそのまま描画される。今回はぼかしを適用して幻想的な感じなので使用