Quick Links: Gideros Home | Download Gideros | Developer Guide
Screen Shake effect? - Gideros Forum
Screen Shake effect?
  • SPDAppsSPDApps +1 -1 (+1 / -0 )
    is it possible to have a screen shake effect in gideros?

    Loves: Gracille

  • glennbjrglennbjr +1 -1 (+5 / -0 )
    Yup. You could do something like this.


    local function shakeScreen()
    stage:setPosition(-10, -10)
    GTween.new(stage, 0.25, {x = 0,y = 0}, {delay = 0, ease = easing.outBounce })
    end
  • @glennbjr nice simple and easy, I might just steal that function for my utilties.lua file lol
    ThumbHurt Games / FB: ThumbHurt Games / FB: Eli/Teranth | Skype: teranth37
  • Hmm, that gives one great idea, simple feature to add to my app.
    Should look cool together with vibrations
    Thanks ;)
  • talistalis +1 -1 (+2 / -0 )
    this is really good, just with one parameter i used it to animate my buttons after onclick.
    Thanks for the idea @glennbjr.
    --will shake the object just pass your button object for test
    function shake(object)
    object:setPosition(object:getX()-3, object:getY()-3)
    GTween.new(obje, 0.25, {x = object:getX()+3,y = object:getY()+3}, {delay = 0, ease=easing.outBounce })
    end
  • talistalis +1 -1 (+1 / -0 )
    @Teranth another treasure for the utilities.lua :ar!

    Loves: chipster123

  • Took a liberty of adding this to FAQ ;)
  • @talis indeed your function is going there for sure, I like the fact you can use it on pretty much any sprite. :)
    ThumbHurt Games / FB: ThumbHurt Games / FB: Eli/Teranth | Skype: teranth37
  • credits go to @glennbjr i just added a parameter to it and changed the coordinates . =D>
  • Thanks @talis and @ glennbjr - that will be useful.

    In case it's any use to anyone else, I've also made a function based on that to pulse the size of a button as that's what I needed for something I'm working on:
    function pulse(object,scl)
    if scl ~= nil then
    object:setScale(scl)
    else
    object:setScale(1.2)
    end
    GTween.new(object, 0.2, {scaleX=1,scaleY=1}, {})
    end

    Has optional scl parameter to set the scale to pulse to (can be less than 1 to make the object smaller). If no scl set, then it defaults to making it 1.2x original size.
  • @petec, neat I will have to test that out too :) Thanks for sharing.
    ThumbHurt Games / FB: ThumbHurt Games / FB: Eli/Teranth | Skype: teranth37
  • @talis

    I tried using your code but i cant shake the Flask image,
    can anyone tell whats wrong with my code? thanks...
    heres my code

    shakey = gideros.class(Sprite)
    function shakey:init()

    local bg = Bitmap.new(Texture.new("images/Main Menu/BG2.png"))
    self:addChild(bg)

    local object = Bitmap.new(Texture.new("images/Main Menu/Flask.png"))
    self:addChild(object)
    object:setPosition(150, 40)
    object:addEventListener ("click",


    function shake(object)
    object:setPosition(object:getX()-3, object:getY()-3)
    GTween.new(obje, 0.25, {x = object:getX()+3,y = object:getY()+3}, {delay = 0, ease=easing.outBounce })
    end)


    local bup = Bitmap.new(Texture.new("images/Backbtn.png"))
    local bdown = Bitmap.new(Texture.new("images/Backbtn1.png"))
    local backbtn = Button.new(bup, bdown)
    backbtn:setPosition(3, 170)
    self:addChild(backbtn)

    backbtn:addEventListener ("click",
    function()
    sceneManager:changeScene("mmenu", 0.3, SceneManager.crossfade)
    end)



  • the error dialog when I run it was this:

    shakey.lua:13: '(' expected near 'shake'
  • I think that this:
    function shake(object) 
    object:setPosition(object:getX()-3, object:getY()-3)
    GTween.new(obje, 0.25, {x = object:getX()+3,y = object:getY()+3}, {delay = 0, ease=easing.outBounce })
    end)


    Should be like this:
    function shake(object) 
    object:setPosition(object:getX()-3, object:getY()-3)
    GTween.new(obje, 0.25, {x = object:getX()+3,y = object:getY()+3}, {delay = 0, ease=easing.outBounce })
    end


    No need for ) at the end of the function
  • @Gracille Addition to @ar2rsawseen post working functions are below. Also iparameter of the function and gtween obje is not same. So here is the working and correct one for sure:)
    P.S : Tested:)
    --change the value 5 to change the shake distance
    function shake(obje)
    obje:setPosition(obje:getX()-5, obje:getY()-5)
    GTween.new(obje, 0.25, {x = obje:getX()+5,y = obje:getY()+5}, {delay = 0, ease = easing.outBounce })
    end
  • thanks for the reply @ar2rsawseen and @talis...

    @talis I tried your code but the error is still the same. :(
  • @Gracille as i said before this is the code i am using in my own applications and it is %100 working.
    In your implementation ther must be something wrong. So please post your whole code here and we can correct.
  • heres my code:

    shakey = gideros.class(Sprite)
    function shakey:init()

    local bg = Bitmap.new(Texture.new("images/Main Menu/BG2.png"))
    self:addChild(bg)

    local object = Bitmap.new(Texture.new("images/Main Menu/Flask.png"))

    self:addChild(object)
    object:addEventListener ("click",

    --change the value 5 to change the shake distance
    function shake(object)
    object:setPosition(object:getX()-5, object:getY()-5)
    GTween.new(object, 0.25, {x = object:getX()+5,y = object:getY()+5}, {delay = 0, ease = easing.outBounce })
    end
    -------
    local bup = Bitmap.new(Texture.new("images/Backbtn.png"))
    local bdown = Bitmap.new(Texture.new("images/Backbtn1.png"))
    local backbtn = Button.new(bup, bdown)
    backbtn:setPosition(3, 170)
    self:addChild(backbtn)

    backbtn:addEventListener ("click",
    function()
    sceneManager:changeScene("mmenu", 0.3, SceneManager.crossfade)
    end)

    end
  • @Gracille you only define the shake function but you didn't call it anywhere.
    You should call the function somewhere like:
    shake(bup)
    shake(backbtn)
    etc....
  • sorry but I'm newbie to gideros and i dont know the other functions...thanks for the reply
  • @Gracille no problem there is nothing wrong with asking and learning. Please feel free to ask anything. If i know i will help, if not someone else will:D
    Time will come and you will answer my questions too. This is what this forum is for \m/
  • Just a thought, have you tried to set the X and Y randomly to an offset of 3 in any direction than using a tween?

    like so http://youtu.be/2_PcbQQYeic

    it is just calling and setting a new position for the object periodically randomly.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters