• Help with Action script 3 Dynamic-light
    1 replies, posted
  • Avatar of Lemmingz95
  • Hey guys, need some help with this dynamic light in AC3, I have the edge of the shape defined but am unable to fill the shape. Process goes something like this; -Send out 90 tracers in an ark. -collision check on every point on each ray -Return length until collision -Draw line from point to point Here's the code; [code]import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.display.MovieClip; var ray:MovieClip = new MovieClip(); var env = new environment(); var arc = 364; var rays = 135; var rayAngleStep = 0; var drawDistance = 150; var rayStep = 5; var dispX = 0; var dispY = 0; stage.addChild(ray); stage.addChild(env); env.x = stage.width; env.y = stage.height; addEventListener(Event.ENTER_FRAME,myEnterFrame); function myEnterFrame(event:Event) { ray.graphics.clear(); ray.graphics.lineStyle(0, 0xff0000, 100); rayAngleStep = arc / rays; ray.graphics.moveTo(mouseX, mouseY); for (var k=0; k<arc; k+=rayAngleStep) { dispX = Math.cos(to_radians(k)); dispY = Math.sin(to_radians(k)); ray.graphics.lineTo(mouseX+dispX*hitTest(dispX,dispY), mouseY+dispY*hitTest(dispX,dispY)); } function hitTest(dx:Number,dy:Number):Number { var retVal = 0; for (var j=0; j<drawDistance; j+=rayStep) { if (env.hitTestPoint((mouseX + dx * j),(mouseY + dy * j),true)) { retVal = j; break; } else { retVal = j; } } return retVal; } function to_radians(n:Number):Number { return (n*0.0174532925); } }[/code] What I need to do is fill the area that should be light, so I can then use it as a mask. The only object is a movieclip containing shapes to block light - called environment. Any help is greatly appreciated.
  • Avatar of Naelstrom
  • It's been a long while since I've used action script, but you'll need to call something like: [code]ray.graphics.clear(); ray.graphics.beginFill(0xFF0000); ray.graphics.moveTo(mouseX, mouseY); ray.graphics.lineTo(mouseX+50, mouseY); ray.graphics.lineTo(mouseX+50, mouseY+50); ray.graphics.lineTo(mouseX, mouseY+50); ray.graphics.endFill();[/code] The code above would draw a red box, dispite me only drawing three lines the endFill() call would close up the shape and fill it.