Mercurial > sdl-ios-xcode
comparison docs/html/guidetimeexamples.html @ 181:e5bc29de3f0a
Updated from the SDL Documentation Project
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 14 Sep 2001 02:41:09 +0000 |
parents | 55f1f1b3e27d |
children | 355632dca928 |
comparison
equal
deleted
inserted
replaced
180:578815880307 | 181:e5bc29de3f0a |
---|---|
86 ><P | 86 ><P |
87 ><PRE | 87 ><PRE |
88 CLASS="PROGRAMLISTING" | 88 CLASS="PROGRAMLISTING" |
89 >#define TICK_INTERVAL 30 | 89 >#define TICK_INTERVAL 30 |
90 | 90 |
91 Uint32 TimeLeft(void) | 91 static Uint32 next_time; |
92 | |
93 Uint32 time_left(void) | |
92 { | 94 { |
93 static Uint32 next_time = 0; | |
94 Uint32 now; | 95 Uint32 now; |
95 | 96 |
96 now = SDL_GetTicks(); | 97 now = SDL_GetTicks(); |
97 if ( next_time <= now ) { | 98 if(next_time <= now) |
98 next_time = now+TICK_INTERVAL; | 99 return 0; |
99 return(0); | 100 else |
100 } | 101 return next_time - now; |
101 return(next_time-now); | |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 /* main game loop | 105 /* main game loop */ |
106 | 106 |
107 next_time = SDL_GetTicks() + TICK_INTERVAL; | |
107 while ( game_running ) { | 108 while ( game_running ) { |
108 UpdateGameState(); | 109 update_game_state(); |
109 SDL_Delay(TimeLeft()); | 110 SDL_Delay(time_left()); |
111 next_time += TICK_INTERVAL; | |
110 } </PRE | 112 } </PRE |
111 ></P | 113 ></P |
112 ></DIV | 114 ></DIV |
113 ></DIV | 115 ></DIV |
114 ><DIV | 116 ><DIV |