How do I make a pause function?

SosaseesSosasees Posts: 22Member

I want to pause/unpause my game per Input.is_action_just_pressed("pause").
I don't want a pause menu yet, since this would make the instructions too complicated to understand.
For now, I only need the game to freeze or unfreeze, no additional menus added.

Best Answer

Answers

  • MegalomaniakMegalomaniak Posts: 2,608Admin
    edited June 28 Accepted Answer

    docs.godotengine.org/en/stable/tutorials/misc/pausing_games.html

    make sure to read the linked page through.
        var is_paused = false
    
        if Input.is_action_just_pressed("pause") and !is_paused:
            get_tree().paused = true
        elif Input.is_action_just_pressed("pause") and is_paused:
            get_tree().paused = false
        else:
            pass
    
  • SosaseesSosasees Posts: 22Member
    edited June 29

    Thanks very much for the answer. Now I can finally pause the game, and it was very simple.
    I only needed to read the Documentation Page and not your code example
    (probably because the code example is already on the Documentation Page).
    I managed to shorten the example code from the Documenation. Now it's only a simple if-statement:

    extends Control
    
    func _process(_delta):
        if Input.is_action_just_pressed("pause"):
            get_tree().paused = !get_tree().paused
            if get_tree().paused == true : $Popup.show()
            if get_tree().paused == false: $Popup.hide()
    

    This is my pause scene:

    Control: "Pause" ๐Ÿ“œ ๐Ÿ‘
      โคท Popup: "Popup"
          โคท RichTextLabel: "Text" ๐Ÿ‘
    

    โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

    If you don't disagree, I'll write you in my game credits:

    ร—ร—ร— Special Thanks to the helpful Answers on the Godot Forums ร—ร—ร—

    Godot Forums Moderator:
    Megalomaniak (Pause Screen)

  • MegalomaniakMegalomaniak Posts: 2,608Admin

    I honestly feel it would be fairer to perhaps give credit to the contributors of the documentation rather than me. ;)

  • SosaseesSosasees Posts: 22Member
    edited June 29

    @Megalomaniak said:
    I honestly feel it would be fairer to perhaps give credit to the contributors of the documentation rather than me. ;)

    Where can I see who contributed to the documentation?

    In the meantime, ,,Special Thanks to the Godot Documentation Contributors" is much better than nothing.

  • TwistedTwiglegTwistedTwigleg Posts: 2,629Admin

    If you go to the Godot GitHub, and then navigate to the file, you can click the History button to see everyone who has contributed, including the first commit, which would be the original author.

    In the case of the pausing tutorial, it is hard to say because the history only goes far enough back to see that the file was moved...

  • MegalomaniakMegalomaniak Posts: 2,608Admin

    @Sosasees said:

    In the meantime, ,,Special Thanks to the Godot Documentation Contributors" is much better than nothing.

    I would think that would suffice, if someone is interested in finding out more specific info they can look for it themselves.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file