Random trouble with pause

Hi, In my game I’ve added a function to pause the whole app.

Here How it looks like: 

[lua]

–PAUSE

    

local pauseBTN = display.newImage(“immagini/pause.png”)

pauseBTN.x = _W/2 + 145

pauseBTN.y = _H/2 + 270

pauseBTN.xScale = 2

pauseBTN.yScale = 2

localGroup:insert(pauseBTN)

local function pause()

    local pauseText = display.newText(“Game Paused”, _W/2-120, _H/2-100, “PUSAB”, 26)

    pauseText:setReferencePoint(display.CenterReferencePoint);

    pauseText:setTextColor(255, 255, 0)

    local tapToReplayText = display.newText(“Tap to resume”, _W/2 - 105, _H/2-50, “PUSAB”, 20)

    tapToReplayText:setReferencePoint(display.CenterReferencePoint);

    tapToReplayText:setTextColor(255, 255, 0)

    

    physics:pause()

    bgSpeed = bgSpeed-1

    coinSpeed = coinSpeed-1

    timer.pause(myTimer)

    timer.pause(tmr)

    

    local fade1 = display.newImage(“immagini/fade.png”)

    fade1.alpha = 0.01

    localGroup:insert(fade1)

    

    local function resume()

    physics.start()

    bgSpeed = 1

    coinSpeed = 1

    timer.resume(myTimer)

    timer.resume(tmr)

    fade1:removeSelf()

    pauseText:removeSelf()

    tapToReplayText:removeSelf()

end

fade1:addEventListener(“touch”, resume)

    

    

end

pauseBTN:addEventListener(“touch”, pause)

[/lua]

My game is quite similar to Doodle Jump, but there are coins that falls from the top to the bottom of the screen and they are meant to be collected by the player.

The problem is that when I tap on the “pauseBTN” (which is the pause button) the whole game become paused, but coins still falling and if I tap the pause button again, they finally stop.

I can’t explain why. Could you help me?

Thanks :smiley:

The touch event gets called multiple times, once when you first touch the button, multiple times if you move your finger around and finally when you pick your finger up.

Try something like this:

local function pause( event )      if event.phase == "ended" then          -- put the rest of your function code here      end      return true end

Thanks, I would try as soon as possible (right now I’m not on my own computer).

It works! :slight_smile:

Whoo Hoo!

The touch event gets called multiple times, once when you first touch the button, multiple times if you move your finger around and finally when you pick your finger up.

Try something like this:

local function pause( event )      if event.phase == "ended" then          -- put the rest of your function code here      end      return true end

Thanks, I would try as soon as possible (right now I’m not on my own computer).

It works! :slight_smile:

Whoo Hoo!