GameMaker: Window commands extension

Yesterday I made a GameMaker: Studio extension that provides a bunch of utility functions:

  • Allows to minimize/maximize/restore the window on demand.
  • Allows to disable/enable minimize button, maximize button, close button, and window movement.
  • Allows to override behavior for when minimize/maximize/close buttons are clicked.

It is available for free via itch.io; Some examples of uses follow.

Minimize the game window

If you've enabled "borderless window" option in Global Game Settings, you might want a custom "minimize" button, but the built-in functions can't offer you one. This extension does, though:

window_command_run(window_command_minimize);

Which is what you would run when the button is clicked and the game should be minimized.

Disable the close-button

This is made easy enough because there's a function just for this:

Create Event:

    window_command_set_active(window_command_close, false);

To re-enable the close-button, you would call the same function but with true as second argument.

Note that while this will disable closing the game via the button or Alt+F4, tools like Task Manager would still work, so you should only use this to hint that current operation should not be interrupted.

Show confirmation dialog on closing the game

Create Event:

    window_command_hook(window_command_close);

Step Event:

    if (window_command_check(window_command_close)) {
        if (show_question("Are you sure you want to exit?")) game_end();
    }

window_command_hook overrides the given command (in this case, close-action), instead changing an internal variable. Then, when window_command_check is called, the variable' state is returned and it is reset, meaning that the function will return true once after the act.

So in this case, when the game detects that a close-button was clicked, it displays a yes/no dialog and closes the game if the user clicks "yes".

Enter fullscreen mode on "maximize"

Oddly enough, this is what the extension was originally made for - utilizing the "maximize" button in an otherwise-not-resizeable application window to allow the user to enter full screen mode in a click.

Create Event:

    window_command_set_active(window_command_maximize, true);
    window_command_hook(window_command_maximize);

Step Event:

    if (window_command_check(window_command_maximize)) {
        window_set_fullscreen(true);
    }

The logic is much akin to what was shown before - the button is enabled and hooked. Then, when it is clicked, the game enters the fullscreen mode.

In conclusion

This is honestly a pretty simple extension that only does a few things, but does them well.

Download (itch.io)

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *