Consuming input for a pause menu

I have been trying to create a pause menu for my game in defold, and while i have gotten the GUI to work, the aspect of actually pausing the game and consuming input has been a difficulty for me.
Could anyone help me in how to get the game to actually pause. I have looked at the input tutorial but have not been able to get it to work and am not sure what part of the code is the bit consuming input.
This is the code i have for the pause menu:

Check out these examples. Scroll down and there’s a pause game example…

https://britzl.github.io/publicexamples/

2 Likes

I’ve had a look at it and i’m not entirely sure what parts of it I need for the actual pausing the game itself and which parts I would need to replace with my own variables and code for my pause menu

1 Like

Collections introduces a game “world” to you.
If you have a collection proxy that spawned that collection, you can set it’s time step, by sending the message to the collection proxy component:

msg.post("#proxy", "set_time_step", {factor = 0, mode = 0}) -- to stop time
-- or:
msg.post("#proxy", "set_time_step", {factor = 1, mode = 0}) -- to return to normal time speed (1)

Documentation: API reference (collectionproxy)

The easiest way is to put your game collection (containing really your game, you main loop, that you want to pause) as separate to the collection where the menu gui is (e.g. main collection) - this way you can change step of the game collection to 0, but still register inputs in the separate collection.

  • main collection
    • main.go
      • main.gui (with main.gui_script) (or pause_menu.gui ?)
      • main.script
      • collection_proxy (of the game.collection)

In the main script you will spawn your game collection and therefore you will have full control over it, from this place you can send the message I pasted above :wink:

Main.gui_script will be your script handling for the pause menu GUI. If user selects there “resume” button, you can disable this GUI of course and send a message to change factor of the proxy to resume to normal speed of the game.collection.

Very rough and quick sequence diagram for such approach:

This approach will make it also easier for you to later on manage other game.collections (transformed then into e.g. “levels”).

If you are looking for a more advanced solution (but I encourage you to learn this anyway), you can check out some screen managers for Defold, that will make it easier for you to manage multiple collections with guis, e.g. Monarch

3 Likes

So is this correct for the main collection?
image
in which case where would I put the proxy msg.post code, i’m not sure where that’s actually meant to go