flash8之後加入了BitmapData類別
從此能搞的效果越來越多,
在這兒介紹一下如何繪製透明色塊
原理很簡單, 在現成的BitmapData物件上, 將另一個透明的BitmapData加上去即可
在 flash 裡使用 copyPixels
從此能搞的效果越來越多,
在這兒介紹一下如何繪製透明色塊
原理很簡單, 在現成的BitmapData物件上, 將另一個透明的BitmapData加上去即可
在 flash 裡使用 copyPixels
/* * author milkmidi * http://milkmidi.com * http://milkmidi.blogspot.com */ package { import com.bit101.components.PushButton; import flash.display.*; import flash.events.MouseEvent; import flash.geom.Point; import flash.geom.Rectangle; [SWF(width = "465", height = "465", frameRate = "41", backgroundColor = "#dddddd")] public class Eraseandredraw extends Sprite{ [Embed(source = 'assets/Demo320x320.jpg')] public static const Texture:Class; private var _container :Sprite; private var toolsize :int = 40; private var tooloffset :int = toolsize * .5; private var origbmp :BitmapData; private var drawbmp :BitmapData; private var erasebmp :BitmapData; private var _cicleMC :Sprite = new Sprite(); public function Eraseandredraw() { _cicleMC.graphics.beginFill(0); _cicleMC.graphics.drawCircle(20, 20, 20); _cicleMC.graphics.endFill(); origbmp = Bitmap(new Texture()).bitmapData; drawbmp = new BitmapData(origbmp.width, origbmp.height, true, 0); drawbmp.draw(origbmp); erasebmp = new BitmapData(toolsize, toolsize, true, 0); _container = addChild( new Sprite()) as Sprite; _container.addChild( new Bitmap(drawbmp)); _container.addEventListener(MouseEvent.MOUSE_DOWN , _mouseDownHandler); new PushButton(this , 320,0,"Rec" , function ():void { erasebmp = new BitmapData(toolsize, toolsize, true, 0); }) new PushButton(this , 320,20,"Circle" , function ():void { setToolShape(_cicleMC); }) new PushButton(this , 320, 40, "change bg color" , function ():void { graphics.clear(); graphics.beginFill( Math.random() * 0xffffff); graphics.drawRect(0, 0, stage.stageHeight, stage.stageHeight); graphics.endFill(); }) } private function setToolShape(pShape:DisplayObject) :void{ erasebmp.fillRect(erasebmp.rect, 0xFFFFFFFF); erasebmp.draw(pShape); erasebmp.copyChannel(erasebmp, erasebmp.rect, new Point(), 1, 8); } private function _mouseDownHandler(e:MouseEvent):void { stage.addEventListener(MouseEvent.MOUSE_MOVE , _mouseMoveHandler); stage.addEventListener(MouseEvent.MOUSE_UP , _mouseUpHandler); _mouseMoveHandler(null); } private function _mouseUpHandler(e:MouseEvent):void { stage.removeEventListener(MouseEvent.MOUSE_MOVE , _mouseMoveHandler); stage.removeEventListener(MouseEvent.MOUSE_UP , _mouseUpHandler); } private function _mouseMoveHandler(e:MouseEvent):void { var _offset :Point = new Point(mouseX - tooloffset, mouseY - tooloffset); var _drawRect :Rectangle = new Rectangle(_offset.x, _offset.y, toolsize, toolsize); drawbmp.copyPixels(drawbmp, _drawRect, _offset, erasebmp, new Point(), false); } } }
留言
還是不太了解...
請問您是否有原始檔可供參考~
^^||
初學者 小笨
貼在筆事本上, 存成.as檔
再用FlashCS4或是Flex發怖即可