Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Gamemaker countdown  (Read 6294 times)

0 Members and 1 Guest are viewing this topic.

ali

Gamemaker countdown
« on: April 12, 2008, 05:23:38 am »
How do I make a countdown? And when it hits 00:00:00 (min/sec/milisec) it ends the game?
Also display the countdown in text on the screen?
Logged

King Tetiro

Leader of Phoenix Heart
Re: Gamemaker countdown
« Reply #1 on: April 12, 2008, 08:03:17 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
You know what Im not too sure. Lemme go check.
Logged
  • Phoenix Heart
Re: Gamemaker countdown
« Reply #2 on: April 12, 2008, 08:22:25 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
create an object
put an alarm event inside the object that increases the variable
then do all that division to get min, sec ,millisec
then put a draw event inside the object and use draw_text to draw it
Logged
Re: Gamemaker countdown
« Reply #3 on: April 12, 2008, 08:26:20 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2374
Actually, that would make a countup... or a timer. Instead, decrease the variable from a certain value.
Logged

Mamoruanime

@Mamoruanime
Re: Gamemaker countdown
« Reply #4 on: April 12, 2008, 08:48:03 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
Actually, that would make a countup... or a timer. Instead, decrease the variable from a certain value.

erm, not really---

While the alarm counts steps, it's only counting steps to figure out when the alarm's event should execute. You do just about anything in the alarm's event, including subtract values...

For example

Alarm[0]'s event could be

Sec =- 1

and it would subtract Sec whenever Alarm[0] counts to 1000 milliseconds
Logged

ali

Re: Gamemaker countdown
« Reply #5 on: April 12, 2008, 05:51:39 pm »
Uh anybody got some code? 8)
Logged

mit

Re: Gamemaker countdown
« Reply #6 on: April 12, 2008, 06:15:24 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Using alarms or decreasing a variable each step wouldn't actually be a proper countdown, since drops in the framerate would affect it. You can use variables like current_time to have a more accurate counter. Remember current_time is in milliseconds.

Start the timer (so create event or whatever)
Code: [Select]
maxtime = 30000 //30 seconds on the clock
start = current_time

Draw event
Code: [Select]
//Draw time remaining in minutes:seconds:milliseconds
draw_text(10,10,
  string( floor( (start+maxtime-current_time) / 60000 ) ) //Minutes
  +":"+
  string( floor( ((start+maxtime-current_time) / 1000 ) mod 60 ) )  //seconds
  +":"+
  string( floor( (start+maxtime-current_time) mod 1000) )  //milliseconds
)


if (start+maxtime<current_time) game_end(); //When the timer reaches 0.

"mod" is to find the remainder of a division. If we mod the number of seconds by 60, we'll remove the "whole minutes" from it (otherwise 2 minutes would be displayed as 120 seconds, etc)

You could actually combine the start and maxtime variables, just thought it would be clearer like that.
« Last Edit: April 12, 2008, 06:17:08 pm by mit »
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Gamemaker countdown
« Reply #7 on: April 12, 2008, 06:20:11 pm »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
This is easy!

create a countdown object and in the step event.
Initialize these vars, cur_time, min, sec;

var cur_time, min, sec, mili;
//Countdown code

cur_time = 10 //This is ten minutes not 10 seconds
cur_time = - min;
cur_time = +sec;
sec += 1;
if sec > 60 { min = -1
sec = 0;
};

now use the draw_text(x,y,string) function, the string can be anything but for this just use cur_time;

Hope that helps, never tested it though.
Logged

ali

Re: Gamemaker countdown
« Reply #8 on: April 12, 2008, 06:26:54 pm »
Works perfectly! Thanks a lot
Logged

ali

More Gamemaker Help
« Reply #9 on: April 13, 2008, 09:05:10 pm »
I didn't want to make another topic and flood this board so:

in the command obj_delete(ind) what is ind? It says it is the index but how do I know what object holds that index or you know yeah

Code: [Select]
obj_delete(ind)
Help please I need this now!
Logged
Re: Gamemaker countdown
« Reply #10 on: April 13, 2008, 10:51:39 pm »
  • The Dark Lord is here...
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 29
The name of the object is a constant which is equal to its index :P. Also there is object_index, which is the object index of the current instance.

BTW, obj_delete will delete completely the object so that you cannot create more instances of it and all its current instances will be destroyed. If you only want to destroy the actual instance, you can use instance_destroy();
« Last Edit: April 13, 2008, 10:53:28 pm by Darth RPG »
Logged
Darth RPG - Feel Dark Side temptation

  • The Legend of Cerda Website

ali

Re: Gamemaker countdown
« Reply #11 on: April 13, 2008, 11:18:54 pm »
The name of the object is a constant which is equal to its index :P. Also there is object_index, which is the object index of the current instance.

BTW, obj_delete will delete completely the object so that you cannot create more instances of it and all its current instances will be destroyed. If you only want to destroy the actual instance, you can use instance_destroy();
yeah someone at gmc told me
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.173 seconds with 62 queries.