Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.display.Sprite;
- import flash.geom.Point;
- import flash.events.MouseEvent;
- import flash.events.Event;
- var lasersArray:Array = [];
- var fadeSpeed:Number = 0.1;
- var laserColour:uint = 0xFF0000;
- var laserThickness:Number = 2;
- var startPoint = new Point(275,400)
- // the point where the laser will start
- stage.addEventListener(MouseEvent.CLICK,mClick)
- stage.addEventListener(Event.ENTER_FRAME,eFrame)
- function mClick(m:MouseEvent){
- // creates a point with the mouse position
- var clickPoint:Point = new Point(stage.mouseX,stage.mouseY)
- drawBeam(clickPoint)
- }
- function drawBeam(cPoint:Point){
- // the main guts of the laser drawing, creates a new sprite to hold the beam
- // draws a line from the start point to the point you pass into it (where you've clicked)
- var s:Sprite = new Sprite();
- addChild(s)
- lasersArray.push(s)
- s.graphics.lineStyle(laserThickness,laserColour)
- s.graphics.moveTo(startPoint.x,startPoint.y)
- s.graphics.lineTo(cPoint.x,cPoint.y)
- }
- // this bit just fades out and removes old lasers.. can stick it in any enter frame event
- // doesn't need its own special one or anything
- function eFrame(e:Event){
- for(var i:int = 0;i<=lasersArray.length-1;i++){
- lasersArray[i].alpha -= fadeSpeed
- if(lasersArray[i].alpha <= 0){
- removeChild(lasersArray[i])
- lasersArray.splice(i,1)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement