Question: How do you quit a game in GameMaker?
Answer
To quit a game in GameMaker, you can use the built-in GameMaker Language (GML) function game_end()
. This function will close the game window and terminate the program. It's very simple to use; just call the function whenever you need to end the game, such as in response to a player's action like pressing an "Exit" button.
Here is an example of how you might use it in code:
// The following would typically be placed in the button's event or a keyboard check conditional if (keyboard_check_pressed(vk_escape)) { // Check if the Escape key was pressed game_end(); // Quit the game }
If you're using GameMaker Studio 2 and want to ensure that the game closes properly on all platforms, you should also consider using the os_set_quit()
function before calling game_end()
. This is particularly important for ensuring consistent behavior on platforms like iOS or Android.
Here's how you might use both together:
// Code to quit the game, potentially in an exit button's Mouse Left Pressed event os_set_quit(); game_end();
By setting os_set_quit()
, you tell GameMaker that the next step should be to close down the game cleanly on mobile devices or other platforms which have specific requirements for exiting applications.
Was this content helpful?
Other Common Game Engines Questions (and Answers)
- Can You Use C# in Unreal Engine?
- Is Unreal Engine Open Source?
- Can Unreal Engine make 2D games?
- Does Unreal Engine Use C++?
- Does Unreal Engine Use Python?
- What Language Does Unreal Engine Use?
- Does Unreal Engine Use JavaScript?
- Does Unreal Engine work on Linux?
- How Do I Uninstall Unreal Engine 5?
- Is Blender or Unreal Engine Better?
- Is Unreal Engine Good for Beginners?
- Does Unreal Engine Work on Mac?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost