GameMaker: Studio

GameMaker: Studio

View Stats:
Help: Countdown timer
What code would I use to input a countdown timer of 5 secs, which would be displayed in the middle of the level before the level begins?
< >
Showing 1-10 of 10 comments
Hmmm well the simplest way to handle this i think would be to set up an alarm on the countdown object to execute every second and changing the value displayed,and then removing the counter when it reaches 0

so something like

CREATE EVENT

time = 5: alarm[0] = 60; // assuming your game is running 60 fps

ALARM 0 EVENT

time -= 1; if (time <= 0) { instance_destroy(); } alarm[0] = 60;

DRAW EVENT

draw_text(x,y,time);
Last edited by Soma; Sep 5, 2017 @ 9:29am
Almond Meal Sep 5, 2017 @ 3:28pm 
I saw in a previous post you wanted it to display 'Start' as well. In that case, use the codes given in the post above but for the alarm change it to something like this:

if time == "Start"
{
instance_destroy();
}
else
time -= 1;

if (time == 0)
{
time = "Start"
}
alarm[0] = room_speed;

Hope this helps.
These are the codes that I have thus far in order to pause the level and everything in it for a few seconds, then the level restarts. I'm just trying to figure out where to input a countdown timer code of 5 secs, which will be displayed in the middle of the screen.

Obj_pause - create:
// capture screen before pause
roombeforepause = surface_create(surface_get_width(application_surface),surface_get_height(application_surface));
surface_copy(roombeforepause,0,0,application_surface)


// Stop everything else from moving
instance_deactivate_all(true);

// I still need these so reactivate them
instance_activate_object(obj_musiccontroller)
instance_activate_object(obj_mouse)


// end of countdown:
alarm[0] = 120

Obj_pause – alarm[0]:

instance_activate_all();

surface_free(roombeforepause)
instance_destroy()

Obj_pause – draw:

// draw old room
if (surface_exists(roombeforepause)) {
draw_set_alpha(1)
draw_surface(roombeforepause,view_xview[0],0)
}

// dim out the screen
draw_set_alpha(0.5)
draw_set_colour(c_black)
draw_rectangle(0,0,room_width,room_height,false)
draw_set_alpha(1)

// draw your countdown here
Almond Meal Sep 5, 2017 @ 8:26pm 
Use the code you have just showed us and add what we have showed you to it.
In the create event, add:

time = 5:
alarm[1] = room_speed

In Alarm 1 add:

if time == "Start"
{
instance_destroy();
}
else
time -= 1;

if (time == 0)
{
time = "Start"
}
alarm[0] = room_speed;

In the draw event, where is says "// draw your countdown here", add:

draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_text(view_wview/2,view_hview/2,time);
draw_set_valign(fa_top);
draw_set_halign(fa_left);

from Alarm 0, !REMOVE! :

instance_destroy()

This should do everything you've asked for. I hope it helps.
Last edited by Almond Meal; Sep 5, 2017 @ 8:28pm
When I entered the codes you told me displayed above, once I entered level one, the entire screen was blank, couldn't see any of my objects. Is there another way of carrying out this action? And also an ERROR came up where it says "from Alarm 0, !REMOVE! :" in the draw event.
Almond Meal Sep 6, 2017 @ 6:14pm 
The room shouldn't be completely blank, it should be dimmed, does that happen at all? The "from Alarm 0, !REMOVE! :" was not intended as code, it was instructions to remove the instance_destroy() from the alarm0.
Last edited by Almond Meal; Sep 6, 2017 @ 6:38pm
I corrected everything, and removed the instance_destroy() from the alarm0 and the screen still went blank when I entered the level.
Almond Meal Sep 7, 2017 @ 4:25pm 
Do you not even see the count down?

Another option would be to put at the top of each event:

If instance_exists(Obj_pause)
exit;

In all objects, practically the step events, mouse and key presses.
Depending on how you made the game, you may also need to set the speed and gravity of the object to 0. If you do change it to this, do not forget to remove the activation and deactivation codes from the Obj_pause as well as the surface capturing and drawing. Basically the Obj_pause will be as Soma and I have suggested.
I don't even see the countdown, the screen just goes blank green.
Almond Meal Sep 7, 2017 @ 4:57pm 
Odd, sounds like the Obj_pause is either deactivating itself when it runs

instance_deactivate_all(true);

(make sure it is set to true) or it is being destroyed before it draws anything.
Or its not set to visible. Make sure that is ticked. Draw events don't run if it is not visible,
< >
Showing 1-10 of 10 comments
Per page: 1530 50

Date Posted: Sep 4, 2017 @ 6:03pm
Posts: 10