Cool Laser Effect

To draw a line in a scene you can use the LayerLine object.

A LayerLine needs to be attached to a layer.

The code would look something like this:

line=New LayerLine( layer ) line.X=100 line.Y=100 line.X2=540 line.Y2=380

Or

line=New LayerLine( layer,100,100,540,380 )

Now this will just draw a generic line but the LayerLine can also be used to create a cool laser effect as seen in the Typoooh example below:

To make the LayerLine draw a laser like that you must tell it to use an image.

In this case multiple images because we want some cool animations:

Local laserBeam:=New Image[]( Image.Load( "asset::frame0000.png" ), Image.Load( "asset::frame0001.png" ), Image.Load( "asset::frame0002.png" ), Image.Load( "asset::frame0003.png" ) )

laser=New LayerLine( layer ) laser.Images=laserBeam laser.Type=2

The Type property determines the drawing style that can either be Stretched ( 1 ), Clipped ( 2 ), Not clipped ( 3 ).

Here is the full example:

#Import "laser.assets/" #Import "" #Import "" #Import "" Using std.. Using mojo.. Using pyro.framework.. Using pyro.scenegraph.. Class MainWindow Extends Window Field camera:Camera Field laser:LayerLine Field layer:Layer Field scene:Scene Method New( title:String,width:Int,height:Int,flags:WindowFlags=WindowFlags.Resizable ) Super.New( title,width,height,flags ) scene=New Scene( Self ) camera=New Camera( scene ) camera.ClearColor=New Color( 0,.1,0 ) layer=New Layer( scene ) Local laserBeam:=New Image[]( Image.Load( "asset::frame0000.png" ), Image.Load( "asset::frame0001.png" ), Image.Load( "asset::frame0002.png" ), Image.Load( "asset::frame0003.png" ) ) laser=New LayerLine( layer ) laser.Images=laserBeam laser.Type=2 End Method OnRender( canvas:Canvas ) Override App.RequestRender() scene.Update() scene.Draw( canvas ) laser.X=camera.VirtualWidth*.5 laser.Y=camera.VirtualHeight*.5 laser.X2=camera.GetMouseLocation( layer ).X laser.Y2=camera.GetMouseLocation( layer ).Y laser.Frame+=.2 End End Function Main() New AppInstance New MainWindow( "Pyro example",1024,768 ) App.Run() End
Run laser example | Download laser example