Laser Beam

Didn’t find any tuts or posts on how to do one hence my post.

I am trying to figure out how to draw a line from ship1 to ship2 and have it onscreen for only say 0.5 seconds while the sound effect plays. I was going to draw say 2 lines over one another with the 2nd line being wider and lower alpha to try and get a cheap glow effect with additive blending.

I can draw a line from point to point but how can i have it be on screen for the firing duration of say 0.5 seconds.

Any pointers, tips, tuts or shared code?

Thanks in advance for your time and assistance,
Gib

@Gib Here’s a simple example. Tap the screen to shoot.


function setup()
    shoot=0
end

function draw()
    background(40, 40, 50)
    if shoot>0 then
        shoot=shoot-1
        lineCapMode(SQUARE)
        stroke(0,255,0)
        strokeWidth(3)
        line(50,50,400,400)
        stroke(0,255,0,80)
        strokeWidth(10)
        line(50,50,400,400)
    end
end

function touched(t)
    if t.state==BEGAN then
        shoot=30
    end
end

@dave1707, thanks bud, that’s it!

Gracias 'migo

@Gib - here’s a post all about timers

https://coolcodea.wordpress.com/2013/04/30/46-timers/

@Ignatz thank-you. You read my mind…

@Gib - I knew you were going to say that :>

@Gib - you might also like this post about shooting

https://coolcodea.wordpress.com/2014/12/18/187-moving-and-shooting-using-modelmatrix/