Timing Question
I''m developing a side scrolling platform game and I just recently added the ability for my guy to jump. Well he''s a pogo stick! He just bounces up and down when you hold down the jump key so I need a way to force him to wait a bit after he lands before he can jump again.
How do I do this?
At first I thought that I could just use a globally tracked "stunned" flag and set it o 15 or something whenever he jumped. Than I could just decrement it each game cycle and not allow him to jump again until it reached zero. Well this seemed to work great but than I realized that it might time out correctly on my computer but it wouldn''t on a slower or faster one.
What I would really like to do is use the timer of whatever indivdual computer the game is running on - however I''ve never done anything like that so some advice on how to implement it would be helpful
Thank you
If you''re using Win32:
Use JumpTime = timeGetTime() when the pogo jumps. Then, when he tries to jump again:
if ( timeGetTime() - JumpTime >= 1000 ) Jump();
timeGetTime() returns a vaule in milliseconds and is precise to within, I think, 5 ms. 1000 ms == 1 s. The value is the ms since your game started, so it won''t go silly on you (it will always go up).
- mallen22@concentric.net
- http://mxf_entertainment.tripod.com/
Use JumpTime = timeGetTime() when the pogo jumps. Then, when he tries to jump again:
if ( timeGetTime() - JumpTime >= 1000 ) Jump();
timeGetTime() returns a vaule in milliseconds and is precise to within, I think, 5 ms. 1000 ms == 1 s. The value is the ms since your game started, so it won''t go silly on you (it will always go up).
- mallen22@concentric.net
- http://mxf_entertainment.tripod.com/
Well I didn''t mean that the character WAS a pogo stick... just that he bounced up and down like one. (he actually kind of looks like the guy from evil dead) but in any event problem solved thanks a ton for the help!
Since it seems like you haven''t "timed" you game yet you should seriosly consider to time it using milliseconds not frames since slower compus has lower fps and faster has higher fps.
Use timeGetTime() as the starter in your game loop (before anything else) and timeGetTime() at the end as well and make all (I mean movement, jump-delay, shoot-delay) depend on this.
If you use this slower compus may loose frames once in a while but faster computers don''t (actually the movement per frame is lesser for them than on a slow machine but thats actually what you want if you design a game for say 30 fps).
Just trim the params (delta-movement blabla) for your computer and try it on a faster and a slower to get it right.
The dictionary is the only place where success comes before work.
Use timeGetTime() as the starter in your game loop (before anything else) and timeGetTime() at the end as well and make all (I mean movement, jump-delay, shoot-delay) depend on this.
If you use this slower compus may loose frames once in a while but faster computers don''t (actually the movement per frame is lesser for them than on a slow machine but thats actually what you want if you design a game for say 30 fps).
Just trim the params (delta-movement blabla) for your computer and try it on a faster and a slower to get it right.
The dictionary is the only place where success comes before work.
Death is lifes way saying your fired.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement