How to draw a glowing "energy beam" ?
BlitzMax Forums/BlitzMax Programming/How to draw a glowing "energy beam" ?
| ||
Im really hoping someone can help me with this... What is need is to be able to "draw" an "energy beam" or "laser beam" kinda effect. Of course I would like this to look much better than just a red or blue line on the screen. I want some sort of "glow" or "plasma" effect if you guys get my drift. I don't know enough about what types of effects are available to me (like lighting and shading and such) to even begin to try this. I'm looking for ideas and/or sample code. Any help would be greatly appreciated! |
| ||
wondering why no one in the know has even bothered answering this.... should this be moved to the beginners forum so he can get an answer. |
| ||
Best way is probably a streched sprite... err i forgot which mode, but the mode that makes sprite roll towards you. Load the sprite as a png with alpha. |
| ||
I believe setting the blend mode of the sprite to multiply (dunno how that's done in BMAX) will add to the effect Bot described. |
| ||
[Edit] Never mind... [/Edit] |
| ||
Have a look at the samples where, under Birdie/misc, there's a glblur and a lighting example. You could create your laser image, colour it then use lightblend. |
| ||
Maybe this will help: Edit: SetLineWidth only works with the OpenGL implementation of Max2D at the moment. SetGraphicsDriver GLMax2DDriver() Local lastTime:Float=MilliSecs() Local timeNow:Float=lastTime Local timeConstant:Float Local powerTime:Float Local alphaTime:Float Graphics 640,480,0 SetBlend ALPHABLEND While Not KeyHit(KEY_ESCAPE) 'Calculate a time constant so program runs at equal speed on all PCs timeNow=MilliSecs() timeConstant=(timeNow-lastTime)/100 lastTime=timeNow 'Depending on how much we add to powerTime and alphaTime, the speed at which the laser changes strength will vary 'The laser's "power" is how quickly it changes from coloured (at the edge) to white (in the middle). 'By using SetAlpha before calling drawLaser, we can make the width of the beam appear to change over time, since 'the edge of the beam becomes transparent at a lower alpha level than the centre of the beam. powerTime :+ timeConstant*20 alphaTime :+ timeConstant*40 SetColor 20,200,20 SetAlpha 0.1+Abs(Sin(alphaTime)*0.35) drawLaser(10,10,300,300,20,0.25+Abs(Sin(powerTime)*0.75)) Flip Cls PollSystem Wend 'Creates a laser effect by drawing a whole series of lines, starting at the specified width and working down 'towards a line only a pixel wide. Each time it draws a line it brightens the colour, which makes the centre 'appear hotter. Function drawLaser(x1,y1,x2,y2,width:Float,power:Float) Local initialWidth:Float=width While (width > 0) SetLineWidth width DrawLine x1,y1,x2,y2,False Local r,g,b GetColor(r,g,b) SetColor(Min(r+(20*power),255),Min(g+(20*power),255),Min(b+(20*power),255)) width :- 1 End While End Function |
| ||
The SetLineWidth function does not appear to work. Added a SetLineWidth command in the DrawLine help code and it does not appear to work there either Found link in bugs reported on this and SetLineWidth only appears to work with openGL |
| ||
very nice code! but how would you check for a collision with this? |
| ||
Note also that setlinewidth is not always supported correctly on all implementations of OpenGL. On one computer I get the proper width and on another I get no increase. |
| ||
I would stretch a 'glowing beam' texture over an increasing poly/surface using Indiepaths TexturedPoly or the SetUV method. |