I’ve got a shaking explode effect that basically blows up a display group so the elements go flying everywhere. Not the same as what you’re looking for, but you’re welcome to crib anything useful from it…
[code]
– 10/1/12 – explode.lua by mpappas
– Takes a display list and explodes it.
– pass in display list, and callBack function
– screen is messed up afterwards, intended for destroy group and destroy message functions
– (screen explodes, exits to callBack screen)
–
module(…, package.seeall)
– states
local STARTUP = 1
local EXPLODE_STAGE1 = 2
local EXPLODE_STAGE2 = 3
local FINISH = 4
– local global vars
local explodeState = STARTUP
local explodeScreen = nil
local callbackScreen = nil
local tickCount = 0
– local function prototypes
local doExplode
local dismissExplode
–
– init function – called to start the screen to explode, callback func when done
function explode(screen, callback)
explodeScreen = screen
callbackScreen = callback – save off vars…
tickCount = 0
explodeState = STARTUP
Runtime:addEventListener( “enterFrame”, doExplode ) – Called 30 times / second…
end
function doExplode(event) – enterFrame handler – does the actual exploding…
tickCount = tickCount + 1
if( explodeState == STARTUP ) then
– start the explosion SFX
audio.play( mojoData._ExplodeAudio1, { channel=mojoData._sfxChannel, loops=0, fadein=0 } ) – explosion sfx
explodeState = EXPLODE_STAGE1
elseif( explodeState == EXPLODE_STAGE1 ) then
if( tickCount < 80 ) then
local shakeX
local shakeY
– Shake everything around…
for index, value in pairs(explodeScreen) do
if( type(value) == “table” ) then
if( value.x ~= nil ) then
–print("value.x == ", value.x)
shakeX = (0.5 - math.random()) * (tickCount*1.2) – Get a shake value…
shakeY = (0.5 - math.random()) * (tickCount*1.2)
value.x = value.x + shakeX
value.y = value.y + shakeY
end
end
end
else
explodeState = EXPLODE_STAGE2
end
elseif( explodeState == EXPLODE_STAGE2 ) then
if( tickCount < 140 ) then
if( explodeScreen.alpha > 0 ) then
explodeScreen.alpha = explodeScreen.alpha - 0.02
end
– make everything fly offscreen
for index, value in pairs(explodeScreen) do
if( type(value) == “table” ) then
if( value.x ~= nil ) then
if( value.x < 320 ) then – fly off to nearest side
value.x = value.x - 16
else
value.x = value.x + 16
end
if( value.y < 320 ) then – fly off to nearest side
value.y = value.y - 16
else
value.y = value.y + 16
end
end
end
end
else
explodeState = FINISH
end
elseif( explodeState == FINISH ) then
explodeState = nil
dismissExplode()
end
return true
end
function dismissExplode() – All done, cleanup and callBack the calling screen
explodeScreen.isVisible = false
Runtime:removeEventListener( “enterFrame”, doExplode ) – Called 30 times / second…
callbackScreen(true) – inform caller we’re done – true means screenRefresh is true (we exploded screen after all…)
callbackScreen = nil
explodeScreen = nil
end
[/code] [import]uid: 79933 topic_id: 35365 reply_id: 140554[/import]