wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 11168
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gameLoop()... why do we need to know last loop time?
 
Similar Threads
zigzag traverse a matrix
Transparent frame using Robot class and its createScreenCapture() method - help pls!
Balls are not moving
Help needed with the Code
Ball Physics implementation.