Bitmap.draw()を使ってみる1
Bitmapにstageの絵柄を書き込む。
Spriteが一つしか無いのに、
画面上には二つある。
左側はSpriteを描いて回転させたもの。
右側はstageに描かれている絵柄を
Bitmapに転写したもの。
♥0 |
Line 29 |
Modified 2010-05-09 05:34:19 |
MIT License
archived:2017-03-10 06:42:23
ActionScript3 source code
/**
* Copyright umhr ( http://wonderfl.net/user/umhr )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6UHj
*/
/*
Bitmapにstageの絵柄を書き込む。
Spriteが一つしか無いのに、
画面上には二つある。
左側はSpriteを描いて回転させたもの。
右側はstageに描かれている絵柄を
Bitmapに転写したもの。
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite {
private var _sp:Sprite;
private var _bitmap:Bitmap;
public function Main() {
_sp = new Sprite();
_sp.graphics.beginFill(0xFF0000,0.5);
_sp.graphics.drawRect(0,0,100,100);
_sp.graphics.endFill();
_sp.x=100;
_sp.y=200;
this.addChild(_sp);
//bitmapの表示エリアを作っている。
var bitmapData:BitmapData=new BitmapData(232,465);
_bitmap=new Bitmap(bitmapData);
_bitmap.x=232;
this.addChild(_bitmap);
this.addEventListener(Event.ENTER_FRAME,onEnter);
}
private function onEnter(event:Event):void {
//Spriteを回転
_sp.rotation++;
//一度、真っ白に戻している。
_bitmap.bitmapData.fillRect(_bitmap.bitmapData.rect,0xFFFFFF);
//stageの内容を書き込んでいる。
_bitmap.bitmapData.draw(stage);
}
}
}