GameMaker: Studio

GameMaker: Studio

檢視統計資料:
RAREMIND ARTWORKS 2017 年 9 月 4 日 下午 6:03
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?
< >
目前顯示第 1-10 則留言,共 10
76561198361584042 2017 年 9 月 5 日 上午 9:27 
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);
最後修改者:Soma; 2017 年 9 月 5 日 上午 9:29
Almond Meal 2017 年 9 月 5 日 下午 3:28 
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.
RAREMIND ARTWORKS 2017 年 9 月 5 日 下午 7:33 
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 2017 年 9 月 5 日 下午 8:26 
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.
最後修改者:Almond Meal; 2017 年 9 月 5 日 下午 8:28
RAREMIND ARTWORKS 2017 年 9 月 6 日 下午 5:33 
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 2017 年 9 月 6 日 下午 6:14 
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.
最後修改者:Almond Meal; 2017 年 9 月 6 日 下午 6:38
RAREMIND ARTWORKS 2017 年 9 月 7 日 上午 5:22 
I corrected everything, and removed the instance_destroy() from the alarm0 and the screen still went blank when I entered the level.
Almond Meal 2017 年 9 月 7 日 下午 4:25 
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.
RAREMIND ARTWORKS 2017 年 9 月 7 日 下午 4:44 
I don't even see the countdown, the screen just goes blank green.
Almond Meal 2017 年 9 月 7 日 下午 4:57 
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,
< >
目前顯示第 1-10 則留言,共 10
每頁顯示: 1530 50

張貼日期: 2017 年 9 月 4 日 下午 6:03
回覆: 10