On Fri, Dec 2, 2011 at 3:06 PM, Miguel Morales <[email protected]>wrote:
> Why are you using timers? That seems needlessly complicated. > Use a game loop that keeps a constant frame rate. > Maintain state in your sprite objects, use the game loop to update this > state. > Then on a separate draw loop draw the sprite according to its state. > > Then you dont have to worry about weird sync issues. > Well, I am using timers with the state design pattern so that when each timer expires I transition to a new state or update a variable. It keeps my code sparated into neat modules. I have a separate draw function which runs after calling update(deltaTime) on the model (sprites). Without timers the code could become a mess with lots of time-keeping variables decremented on each update to the game loop and lots of tests to see which state the sprites are in accordingly... > > On Fri, Dec 2, 2011 at 5:45 AM, John Goche <[email protected]>wrote: > >> >> Hello, >> >> I have an android game which uses timers to update the screen sprites. >> When the user wishes to pause the screen I have to know which timers >> are pending and how long is missing before their expiration time. So this >> means I have to maintain separate data structures for each Handler to >> keep track of: >> >> A. when the timer is set (timerSetTime) with System.nanoTime() and >> B. how long before it expires (timerExpirationLength) so that >> >> when the user pauses the game screen I cancel all timers >> and then when the user unpauses for each paused timer I compute >> >> unpauseTime = System.nanoTime() >> >> and then reset each timer to timerExpirationLength - unpauseTime + >> timerSetTime >> >> and then when each timer expires unload the corresponding (timerSetTime >> and timerExpirationLength) >> data structure entry in the Handler subclass. >> >> OK, I have described my solution to the problem. The android Handler >> system does not seem >> to provide a custom solution to this problem so I had to implement my own >> code. If anyone has >> a better solution to the problem of dealing with game state timers when >> the game is paused (so >> that they are saved as part of the game state) I'd like to hear your >> alternative solutions. >> >> Thanks, >> >> >> John Goche >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en > > > > > -- > ~ Jeremiah:9:23-24 > Android 2D MMORPG: http://solrpg.com/, > http://www.youtube.com/user/revoltingx > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

