2011年11月21日 星期一

[AS3] 殘影效果拖曳_BitmapData.colorTransform()、draw()

BitmapData.colorTransform()
BitmapData.draw()


1001121_shadow

import flash.geom.ColorTransform;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.Graphics;

var xPos:int = 0;
var yPos:int = 0;

var ctf:ColorTransform = new ColorTransform(.99, .99, .99, .88);
var bmd:BitmapData = new BitmapData(550,400,false,0xffff00);
var bm:Bitmap = new Bitmap(bmd);
var rec:Rectangle = new Rectangle(0,0,bmd.width,bmd.height);
addChild(bm);

var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xffff00,1.0);
circle.graphics.drawCircle(50,50,20);
circle.graphics.endFill();
var container:Sprite = new Sprite();
container.addChild(circle);

this.addEventListener(Event.ENTER_FRAME,loopHandler);

function loopHandler(event:Event):void{
 bmd.colorTransform(rec,ctf);
 xPos += (mouseX - xPos) / 12;
    yPos += (mouseY - yPos) / 12;
 bmd.draw(container);
 circle.x = xPos;
 circle.y = yPos;
 return;
}

沒有留言: