• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rob Poulos
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:





 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic