在做开发的时候遇到了图形镜像的问题,感觉这个不难但是写起来应该是挺麻烦的。不过看了网上的一篇文章以后发现其实解决的方法是很多的。
1 var container:Sprite = new Sprite(); 2 var brush:Sprite = new Sprite(); 3 //设置镜像中心点的位置set mirror center 4 brush.x = 600/2; 5 brush.y = 400/2; 6 container.addChild ( brush ); 7 addChild ( container ); 8 9 var canDraw:Boolean = false;10 var pen:Graphics = brush.graphics;11 12 //复制镜像部分 copy mirror13 var mirrorBmd:BitmapData = new BitmapData(600,400,true,0x00ffffff );14 var mirrorImage:Bitmap = new Bitmap( mirrorBmd );15 addChild ( mirrorImage );16 //镜像的数量17 var mirrorNum = 8;18 //镜像生成函数19 function showMirrorImage () {20 var angle = 360 / mirrorNum;21 mirrorBmd.draw ( container );22 for (var i:int = 1; i < mirrorNum; i++) {23 brush.rotation = angle * i;24 mirrorBmd.draw ( container );25 }26 brush.rotation = 0;27 }28 29 stage.addEventListener ( MouseEvent.MOUSE_DOWN, beginPaint );30 stage.addEventListener ( MouseEvent.MOUSE_MOVE, onPaint );31 stage.addEventListener ( MouseEvent.MOUSE_UP, endPaint );32 function beginPaint (_evt:MouseEvent ) {33 canDraw = true;34 pen.lineStyle (1, 0x006699, 0.75, true, "normal", CapsStyle.ROUND, JointStyle.ROUND, 0.5);35 pen.moveTo (brush.mouseX, brush.mouseY);36 }37 function onPaint ( evt:MouseEvent ) {38 if ( canDraw ) {39 pen.lineTo ( brush.mouseX, brush.mouseY );40 showMirrorImage ();41 }42 }43 function endPaint ( evt:MouseEvent ) {44 if ( canDraw ) {45 pen.lineTo ( brush.mouseX, brush.mouseY );46 pen.clear ();47 canDraw = false;48 }49 }