Make an active Pause Image?

How i can make an active pause image?

I’ve added the image in the game, but the big question is how to make it active, when it’s clicked to pause the game.

I’ve added this in the code, but im not sure is it correct:

pause.id = “pause”

local function onObjectTouch( event )

    if ( event.phase == “began” ) then

        print( "Touch event began on: " … event.target.id )

    elseif ( event.phase == “ended” ) then

        print( "Touch event ended on: " … event.target.id )

    end

    return true

end

object:addEventListener( “touch”, onObjectTouch )

^^With this now, when i click it print text. But how to make it to stop the game?

It depends how your game works. Probably you need remove/add event listeners, pause/resume timers and transitions

It’s a simple game, the first from lessons here - Balloon Tap. I improved it, and yea :smiley:

I just want to stop falling the balloon with the pause

You can also try physics:pause() or stop() to cancel the fall of all the ballons.

If it’s only the ballon that have been touch, you can try ballon.isBodyActive=false.

As others have pointed out you can’t just stop and resume easily.  What I do is have a variabe called isRunning and set that to true when the game starts.  I then simply add this to event handlers, timers, etc.

function myEventHandler()   if isRunning then     --dostuff   end end

The reason I do this is I don’t have to code add/remove code and remember to keep it updated as I add more functionality.  I just need to always include the simple if isRunning check.  I don’t use physics though.

How do you solve problem with transitions? 

In my last game I use one main loop to update all objects from one frame to next one. So I just need stop my loop to pause game.  I don’t use physics in it.

Normally I just cancel them.  I then have a function to restart everything.

It depends how your game works. Probably you need remove/add event listeners, pause/resume timers and transitions

It’s a simple game, the first from lessons here - Balloon Tap. I improved it, and yea :smiley:

I just want to stop falling the balloon with the pause

You can also try physics:pause() or stop() to cancel the fall of all the ballons.

If it’s only the ballon that have been touch, you can try ballon.isBodyActive=false.

As others have pointed out you can’t just stop and resume easily.  What I do is have a variabe called isRunning and set that to true when the game starts.  I then simply add this to event handlers, timers, etc.

function myEventHandler()   if isRunning then     --dostuff   end end

The reason I do this is I don’t have to code add/remove code and remember to keep it updated as I add more functionality.  I just need to always include the simple if isRunning check.  I don’t use physics though.

How do you solve problem with transitions? 

In my last game I use one main loop to update all objects from one frame to next one. So I just need stop my loop to pause game.  I don’t use physics in it.

Normally I just cancel them.  I then have a function to restart everything.