aspose file tools*
The moose likes Game Development and the fly likes gameLoop()... why do we need to know last loop time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "gameLoop()... why do we need to know last loop time?" Watch "gameLoop()... why do we need to know last loop time?" New topic
Author

gameLoop()... why do we need to know last loop time?

Rob Poulos
Ranch Hand

Joined: Aug 21, 2009
Posts: 49
so im checking out the SpaceInvaders tutorial found here:

http://www.cokeandcode.com/node/6

im trying to wrap my head around why you need to know the last loop time to calculate movement? i would think that you would just need to look at the current position and increment that x-axis and/or y-axis by .01, 1, 30 or whatever needed for each loop.

below are a few snippets of the code listed in the above link:







SCJA, ITIL V3 Foudation, Studying for SCJP6
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

All the loops may not be constant in time, depending on what else the machine is doing, but you still want your sprites to look like they are moving at a constant rate.

so if i update the screen more often (i.e. shorter loop times), i want them to move less. 5 frames per second need to move further between each re-paint than 20 frames per second.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
 
subject: gameLoop()... why do we need to know last loop time?