hi all
can anyone explain the logics of it.
i know its used to set the speed to the same on all machines.
but what is the best way to do this?
hi all
can anyone explain the logics of it.
i know its used to set the speed to the same on all machines.
but what is the best way to do this?
Oke, whe have a variable called time wich holds the time
the program is running in milliseconds, if you want an object
to move at a certain speed, you make a variable that is
time+500 and you check everytime if the time is less or equal
to time, if so you move your object, then you make the variable
again time+500 and so on, know what i mean?
I'm not quite sure what you need to be clarified.
You base your animations/physics, etc. on time rather than on how many times the game has looped.
For instance, if you want a 2D sprite animation to advance frames at a rate of 20 per second, you check how much time has passed since the animation started to see what frame should be displayed.
If you had based it on the gameloop rather than time, then the speed at which the animation was played would vary.
The same goes for just about everything else in the game -- walking speed, physics, etc.
There really is no "best" way, but basically what you want to do is poll the time once per game loop (not multiple times per loop because you want each game loop to be a "freeze-frame" in time). You then compare that time to things like the start of an animation or use it to figure out the new location of a player by adding to his location his direction times his speed times amount of time passed, etc.
Last edited by Polymorphic OOP; 12-21-2002 at 10:31 AM.
You use Allegro right?
thanks m8,s
just 1 thing
what time function can i use to get
the time in seconds?
For simplicity you can use GetTickCount() ( #include<windows.h> ) to get time in milliseconds, or you can use the performance clock.
That is, of course, only if you are programming for windows, though.
In seconds i don't know, for milliseconds use time.h and then the
variable clock() holds the time from the start of the program in
milliseconds, you'de better use milliseconds anyhow otherwise
you're have a real slow moving object
yes i'm allegro!
Then you could use Allegro's timers to update movement
so many times per second
yeah but i understand them that well
btw it worked just fine with the clock function.
i managed to pause the game aswell when a key is pressed
but u will have to hold down the key to stay paused any idea how i can fix this
i've seen a function called stimulate keypress or something i allegro
should i use that for this pourpuse?
anyways that would'nt look good
You've got a new message, anyway also this can be fix
using timers, when the key is pressed pause the game,
then don't check for the pause key another say 300 milliseconds
You don't want to do that, it won't solve the problem. You're best off keeping a flag that holds whether or not the key was down in the last loop and a flag saying the game is currently paused. You pause the game when the person presses the pause key and set the flag saying the key is down and the flag saying that the game is paused and then unpause when the person presses the key again -- however, don't count the press for the pause key again if it was down during the last loop because the person probably just held the button down -- same logic goes for unpausing.Originally posted by Travis Dane
You've got a new message, anyway also this can be fix
using timers, when the key is pressed pause the game,
then don't check for the pause key another say 300 milliseconds
Yeah, i know that's a better thing, however this is
undoable or VERY hard to do in allegro, of course you
could use directx for keyboard input
i came up with this:
Code:int time1=0; int time2=time1+500; time2=clock(); while(! key[KEY_ESC]) { time2--; while(time2<=time1) { if(time2<=time1) { time2=time1+500; } //do the drawings and so on... }
is this a good way to do it
cause im not sure of
time2=clock();
gives the right time in
m.seconds
i mean will it be the same on any computer?
You're kinda missing the point. What you did there was not time-based. All you did was poll time once and then went by loop-count instead. With each iteration you should update your time: don't increment the timer manually because a "loop" isn't always the same length.
Edit: There's actually a lot more wrong with it than that. You might wanna go back rethink your logic on it.
Last edited by Polymorphic OOP; 12-21-2002 at 02:40 PM.