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 )
Lastly, I give the option to turn it off with a settings.shakeeffect boolean variable.