Hello,
Does anyone know how to simulate "shaking" effect on background? Like there's some sort of earthquake shaking land?
any help is appreciated
Hi guys,
@darkconsoles, sorry to be posting here into your topic but I think that my doubt links with yours as well.
So @gtatarkin, firstly thanks for this piece of code, but wouldn`t this code "shake" all the display objects instead only the background image? If so how would I set exactly which object I want to shake?
PS: Sorry if I misunderstood something as well as I am just a starter. :)
Cheers,
Rodrigo.
As you see:
1 2 | function(event) rightTrans = transition.to(stage ... function(event) leftTrans = transition.to(stage ... |
object (or group of objects) named stage is shaken so if you do something like this:
1 2 3 4 | local myBackgroundImage = display.newImageRect("link-to-bckg-image.png", 960, 640) myBackgroundImage.x = 480 myBackgroundImage.y = 320 local stage = myBackgroundImage |
Hey @gtatarkin,
I got it now!! :)
Thank you. So much appreciated for sure.
Regards,
Rodrigo.
@gtatarkin, awesome code, thanks for sharing.
I just implemented this in a game, where if my character grows bigger (powerup) and lands on a platform I shake the screen a bit.
here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | --shaking effect local stage = display.getCurrentStage() local originalX = stage.x local originalY = stage.y local moveRightFunction local moveLeftFunction local rightTrans local leftTrans local originalTrans local shakeTime = 50 local shakeRange = {min = 1, max = 3} local endShake moveRightFunction = function(event) rightTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max), y = math.random(shakeRange.min, shakeRange.max), time = shakeTime, onComplete=moveLeftFunction}); end moveLeftFunction = function(event) leftTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max) * -1, y = math.random(shakeRange.min,shakeRange.max) * -1, time = shakeTime, onComplete=endShake}); end moveRightFunction(); endShake = function(event) originalTrans = transition.to(stage, {x = originalX, y = originalY, time = 0}); end --end shaking effect |
Thanks for posting this. It worked perfectly.
thanks, i'll try it
i didnt even think about using display.getCurrentStage, thanks)