Anyone Ever Created A Camara Shake Effect?

Just curious, it would be a lovely addition to my game… So, just wondering if anyone had achieved it without 10,000 transitions… I was thinking something along the lines of…

<lua>

local function cameraShake( event )
local now = system.getTimer()

myGroup.xScale  = 1.2 + Sin(now/400)*0.5
myGroup.yScale  = 1.2 + Cos(now/320)*0.5
   

end
   

Runtime:addEventListener( “enterFrame”, cameraShake)

</lua>

There’s probably a way of achieving a nicer effect, any ideas?

Also, anyone know why my LUA tags aren’t working?

Use the word  code in <> instead, don’t think the word  lua works.

Anyhoo, I use a screen shake all the time.  Looks great in my upcoming game, Archangel: Fate of the Galactic Commonwealth.

http://www.youtube.com/watch?v=AguuVRh-8tY&t=3m40s

(fast-forward to 3:40 to the a reverse of the screen shake function I made)

I add everything to a shakeable display group, store it’s original location as .originalX and .originalY , then with an enterFrame event listener, I do a check with a variable called shakeamount :

if settings.shakeeffect and shakeamount \> 0 then local shake = math.random( shakeamount ) shakeable.x = shakeable.originalX + math.random( -shake, shake ) shakeable.y = shakeable.originalY + math.random( -shake, shake ) shakeamount = shakeamount - 1 end

I usually don’t go more than 20 so the screen doesn’t get too crazy.  I use my clamped function like this:

local function clamped( value, lowest, highest ) return math.max( lowest, math.min( highest, value ) ) end ... audio.play( explosion\_sound ) shakeamount = clamped( shakeamount + 10, 0, 20 ) &nbsp;

Lastly, I give the option to turn it off with a settings.shakeeffect  boolean variable.

Thanks Raphael that’s excellent. Loving that slide-zoom function too. Good luck with the game it rocks!

Also, anyone know why my LUA tags aren’t working?

Use the word  code in <> instead, don’t think the word  lua works.

Anyhoo, I use a screen shake all the time.  Looks great in my upcoming game, Archangel: Fate of the Galactic Commonwealth.

http://www.youtube.com/watch?v=AguuVRh-8tY&t=3m40s

(fast-forward to 3:40 to the a reverse of the screen shake function I made)

I add everything to a shakeable display group, store it’s original location as .originalX and .originalY , then with an enterFrame event listener, I do a check with a variable called shakeamount :

if settings.shakeeffect and shakeamount \> 0 then local shake = math.random( shakeamount ) shakeable.x = shakeable.originalX + math.random( -shake, shake ) shakeable.y = shakeable.originalY + math.random( -shake, shake ) shakeamount = shakeamount - 1 end

I usually don’t go more than 20 so the screen doesn’t get too crazy.  I use my clamped function like this:

local function clamped( value, lowest, highest ) return math.max( lowest, math.min( highest, value ) ) end ... audio.play( explosion\_sound ) shakeamount = clamped( shakeamount + 10, 0, 20 ) &nbsp;

Lastly, I give the option to turn it off with a settings.shakeeffect  boolean variable.

Thanks Raphael that’s excellent. Loving that slide-zoom function too. Good luck with the game it rocks!

Very cool effect Raphael. Thanks!

Very cool effect Raphael. Thanks!