The adventure continues!
In today’s post I will show you how I made an in-game menu with a slow-motion feature in Game Maker Studio.
Before starting: I hope you keep your game’s objects/scripts/variables organized because if you have a lot of already hardcoded variables you are going to have a hard time.
Let’s start with the description: when a player clicks “ESC” an in-game menu opens and time “slows-down”. Slowing down time means changing the movement_speed, image_speed and alert timers of all the objects to 1/10 (or whatever you want) of its original speed resulting in the effect of time being slowed down.
In my project I used my object obj_orchestrator which keeps track of the players progress (waves, monsters, etc.) to create the global variable timeMultiplier.
This variable is then added to the movement actions and alerts of all Objects.
Your code for the movement actions should look like this:
x += movement_speed*timeMultiplier
and your code for the alerts should look like this:
alert[n] = cooldown*room_speed*(1/timeMultiplier)
the formula for the alert is different because it works like a cooldown meaning we need to do the opposite and make the timer longer.
Then I added an event (Click ESC) to the obj_orchestrator which changes the Global variable timeMultiplier to timeMultiplier/5 and the end result looks like this:
Now all that’s left is the menu and the options, beginning with the menu which you can see in the video above.
My menu object contains 2 events: step and create, I used the step event to make the menu move into it’s final position and the create event to set a bunch of variables.
Step Event code:
if(x > target_x and obj_orchestrator.pause)
x -= x_changer
x_changer *= 0.9
x_changer *= 0.9
The changer is used to give the fast start, slow finish effect.
And after that I had to code in the buttons (options), In my case I wanted the menu options to be clickable so I had to separate the options into objects called obj_button.
Of course the button had to move with the Menu so I added the same slide-in system to it. To make the buttons clickable I added an “if statement” checking if the position of the mouse is inside a rectangle covering the text (because draw_text does not have a collision box). This code is placed in the Draw Gui event.
Here’s the code:
var wx = window_mouse_get_x();
var wy = window_mouse_get_y();
show_debug_message("mouse_x: " + string(wx) + " menu_x: " + string(menu_x))
if point_in_rectangle(wx, wy, menu_x - text_width/2, menu_y, menu_x + text_width/2, menu_y + text_height)
if(text == "Exit")
draw_text(menu_x, menu_y, text)
When we know the mouse is over the “Exit” button we just add an
if(mouse_check_button_pressed(mb_left)) and confirm that the button text contains “Exit”, then we run
game_end() to close the game.
The end result looks like this:
That’s it for today’s post, hope I explained it well enough and if I didn’t you can write to me on firstname.lastname@example.org!