System.currentTimeMillis is not the correct way to go for games, it changes if the users changes the time on the phone. Use SystemClock.uptimeMillis
http://developer.android.com/reference/android/os/SystemClock.html#uptimeMillis() On Jan 14, 7:14 pm, Robert Green <rbgrn....@gmail.com> wrote: > private long tickMs; > private long lastTickMs; > private long tickDeltaMs; > > public void run() { > while (running) { > lastTickMs = tickMs; > tickMs = System.currentTimeMillis(); > tickDeltaMs = tickMs - lastTickMs; > updateGame(tickDeltaMs); > } > > } > > That's all you need. I've found that the actual tick time doesn't > matter but the difference between the last tick and this tick is all > you need to have correct physics and most any update I've had to write > so far. > > Game physics can work like this > > updateGame(12) // moves physics 12ms forward > updateGame(15) // moves physics 15ms forward > updateGame(22) // moves physics 22ms forward > > That's exactly what you want the tick delta for. I use that for all > movement, sound, collisions, animations and timers. > > There's one exception - if your game cares about time of day. Then > you need the actual time of day calculated out to use for it, but > otherwise if the game runs in its own time, that'll do. > > On Jan 14, 7:02 am, Neilz <neilhorn...@googlemail.com> wrote: > > > > > Hi all. What is most efficient way of keeping a check on time within a > > game thread? > > > Currently I create a new Date() when the game starts, and was thinking > > of creating another Date() within the game thread and comparing it > > with the first one. But with a screen refreshing at around 60fps > > (hence a new date object each time), I can't help thinking this is > > rather inefficient. What other ways are there of doing this?
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en