Page 1 of 6

Camera Shake? / Collisions / Enemies...

Posted: Sat Nov 06, 2010 8:13 pm
by Ryne
Hi guys. Here is a screenshot of what Ive been working on for the last few days. I'm wondering if I could create a "Camera Shake" effect for explosions such as grenades or mines. I was thinking that I would actually have to create a "camera" somehow that I could actually "shake" unless there is an easier way to achieve the desired effect?

Thanks guys!

Image

Re: Camera Shake?

Posted: Sat Nov 06, 2010 8:20 pm
by bartbes
You probably want to play with love.graphics.translate and love.graphics.rotate.

Re: Camera Shake?

Posted: Sat Nov 06, 2010 8:23 pm
by nevon
That looks so very, very good.

Re: Camera Shake?

Posted: Sat Nov 06, 2010 8:55 pm
by Robin
Looks great!

And such an effect is easily done with translate, as bartbes said. I use it in Space as a sign you're too close to a black hole. I think I used something like:

Code: Select all

love.graphics.translate(math.random(horiz_amplitude*2)-horiz_amplitude, math.random(vert_amplitude*2)-vert_amplitude)
If you don't want the UI to shake as well, use something like:

Code: Select all

love.graphics.push()
love.graphics.translate(math.random(horiz_amplitude*2)-horiz_amplitude, math.random(vert_amplitude*2)-vert_amplitude)
-- draw game stuff here
love.graphics.pop()
-- draw UI things here

Re: Camera Shake?

Posted: Sat Nov 06, 2010 9:00 pm
by zac352
Robin wrote:Looks great!

And such an effect is easily done with translate, as bartbes said. I use it in Space as a sign you're too close to a black hole. I think I used something like:

Code: Select all

love.graphics.translate(math.random(horiz_amplitude*2)-horiz_amplitude, math.random(vert_amplitude*2)-vert_amplitude)
If you don't want the UI to shake as well, use something like:

Code: Select all

love.graphics.push()
love.graphics.translate(math.random(horiz_amplitude*2)-horiz_amplitude, math.random(vert_amplitude*2)-vert_amplitude)
-- draw game stuff here
love.graphics.pop()
-- draw UI things here
Doing something like that would look really bad if you were doing several pixels. Every single frame. It'd look like a big blur.

Re: Camera Shake?

Posted: Sat Nov 06, 2010 9:03 pm
by Robin
zac352 wrote:Doing something like that would look really bad if you were doing several pixels. Every single frame. It'd look like a big blur.
Actually, not really. It works pretty well in Space, check it out. (Or fork me, whatever.)

Re: Camera Shake?

Posted: Sat Nov 06, 2010 9:10 pm
by zac352
Robin wrote:
zac352 wrote:Doing something like that would look really bad if you were doing several pixels. Every single frame. It'd look like a big blur.
Actually, not really. It works pretty well in Space, check it out. (Or fork me, whatever.)
Can has video?

Re: Camera Shake?

Posted: Sat Nov 06, 2010 9:12 pm
by Robin
Can has LÖVE. I somehow doubt that a screencast of camera shaking effects will be very interesting.

Re: Camera Shake?

Posted: Sat Nov 06, 2010 10:32 pm
by Ryne
Thanks for the comments guys! I'll try this code when I get home and try to get a demo up sometime this week. :)

Also, for those who were curious of the random white circle, it's the cursor for the game. ;)

Re: Camera Shake?

Posted: Sat Nov 06, 2010 10:59 pm
by zac352
Ryne wrote:Thanks for the comments guys! I'll try this code when I get home and try to get a demo up sometime this week. :)

Also, for those who were curious of the random white circle, it's the cursor for the game. ;)
Looks fun. *waits for download*