Animate Buttons

I tried to add effects on my buttons when I click them, so I created a function to animate the buttons when they are clicked.

 

Here’s the code to animate the buttons:

 

doanim = function(obj) – global function to animate buttons

    local obj = obj
    transition.to(obj, { time = 100, xScale = 1.2, yScale = 1.2 })
    transition.to(obj, { delay = 100, time = 300, xScale = 1, yScale = 1 })
end

 

Here’s the code to handle when the button is touched:

 

local touchHelp = function(event) – function to handle touching of help button
    local obj = event.target
    if event.phase == “ended” then
        doanim(obj) – animate button
        audio.play(sounds.popsound) – play pop sound
        storyboard.gotoScene(“help”, “fromBottom”, 300)
    end
end

 

 

I added sound and animation for the clicked buttons and it works fine.

 

Now I want to add more effects to it but I am stuck. My buttons are made up of bubbles and I want to add a popped-bubble effect on to the buttons when they are clicked. I have an image file for a “splashed bubble” effect and I want to add this effect when the buttons are clicked.

 

I have seen someone doing it like this from one of the older forums but I still don’t get it  :frowning:

function bubble:Pop()
    if(self.collision)then
        self:removeEventListener(“collision”, self)
    end
    if(self.touch)then
        self:removeEventListener(“touch”,self)
    end     local bubblePop = display.newImageRect(self.gfxGroup, “BubblePop.png”, 250, 250)
    bubblePop.x = self.x
    bubblePop.y = self.y
    bubblePop.xScale = .01
    bubblePop.yScale = .01
    transition.to(bubblePop, {time=150, xScale = 1, yScale = 1, alpha = 0, onComplete = function()
    display.remove(bubblePop)
    bubblePop = nil
    end})     display.remove(self)
    self = nil
end

Have you tried to do it with sprites?

When you push the button, play the sequence of the sprite.

 

I haven’t tried with sprites yet… I shall try it soon

Thanks :slight_smile:

Have you tried to do it with sprites?

When you push the button, play the sequence of the sprite.

 

I haven’t tried with sprites yet… I shall try it soon

Thanks :slight_smile: