Need help with loop timing / delays
Agent420
Posts: 439
I'm working on my Prop Invaders app...· I've got a main loop that processes different functions based on time delays so I can somewhat regulate the function timing.· As many methods can require varying cycles to complete, I thought I would base these delays on the system timer rather than simply counting iterations through the main loop.· But I am experiencing some bug issues where my code either hangs for a while or rapidly executes - this seems to be potentially where my references to the system cnt are either wrapping by zero or Spin may be interpreting cnt values > $80000000 as negative.· Either way, I am obviously not handling this correctly.
Here is an example of my main loop operation:
I have several timer variables for different methods, such as bonus_timer, bomb_timer, missile_timer etc.· They are all reset similarly when their respective method is called by adding a predetermined delay value to the current system cnt:
The idea is that the bomb_timer value can now be used as a reference in the main loop so that the code is only called after a certain period of time has passed.·
Any ideas on how to·better implement this kind of timing?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Agent420) : 9/23/2009 11:02:13 AM GMT
Here is an example of my main loop operation:
repeat if (bonus) AND (cnt > bonus_timer) row:=4 'erase bonus score col:=bonus-1 printstr(string(" ")) bonus:=0 'reset bonus flag if ((bomb_color) AND (cnt > bomb_timer)) ' Only do if a bomb is onscreen (bomb_color != 0) ' AND if bomb_timer time interval has passed (slow down bomb) if (move_invader_bomb) if (kill_player) 'bomb hit player game_over
I have several timer variables for different methods, such as bonus_timer, bomb_timer, missile_timer etc.· They are all reset similarly when their respective method is called by adding a predetermined delay value to the current system cnt:
PRI move_invader_bomb | i, j, tile 'returns True if bomb hits player base bomb_y-- 'move bomb bomb_timer := bomb_delay+cnt 'reset timer
The idea is that the bomb_timer value can now be used as a reference in the main loop so that the code is only called after a certain period of time has passed.·
Any ideas on how to·better implement this kind of timing?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Agent420) : 9/23/2009 11:02:13 AM GMT
Comments
Your example seems to have resolved my problem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔