效果:
源码:
package { import flash.display.MovieClip; public class Main extends MovieClip { public function Main() { // constructor code var antLine:AntLine = new AntLine(400, 200); addChild(antLine); //flash里用线条做遮罩为什么没有用?答:线条不能做遮罩,选中线条在修改-形状-将线条转换为填充。这样就可以了。 var antLine2:AntLine = new AntLine(400, 200); addChild(antLine2); antLine2.y = 250; antLine2.mask = mc; } } } import flash.display.Sprite; import flash.events.Event; class AntLine extends Sprite { private var _w:int; private var _h:int; public function AntLine(w:int,h:int){ setSize(w,h); } public function setSize(w:int, h:int):void { _w = w; _h = h; addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private var _offset:Number = 0; private function enterFrameHandler(e:Event):void { _offset += 0.5; update(); } private function update():void { graphics.clear(); graphics.lineStyle(2, 0x000000, 1.0); var len:int = _w + _h; var x1:Number = i; var y1:Number = 0; var x2:Number = 0; var y2:Number = i; _offset = _offset % 6; for (var i:int = _offset; i < len; i += 6 ) { x1 = y2 = i; if (i>_w) { x1 = _w; y1 = i - _w; } if (i>_h) { y2 = _h; x2 = i - _h; } graphics.moveTo(x1, y1); graphics.lineTo(x2, y2); } } }
实现原理:
参考:http://blog.kanguowai.com/post/54
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。