November 2011
Beginner
196 pages
5h 3m
English
Now you can move on to create a system that enables you to accurately set how quickly your game runs. No longer will the game loop be subject to the whims of the device. To do this, you use a timer and then adjust the movement based on how much time has elapsed. This means that if one cycle takes a very long time and another takes a short amount of time, the sprite will move a certain distance depending on that value. Looking at the code is the best way to understand this type of method. Follow these steps:
- Replace the code in the
synchronizedblock inGameLogic.javawith the code in Listing 2-13.Listing 2-13. Testing a Constant FPS Game
try { Thread.sleep(30); } catch (InterruptedException e1) { } ...
Read now
Unlock full access