Game Development Reference
In-Depth Information
time has passed since the last update. So, our MySuperAwesomeStartScreen.update() method
should look like this:
@Override
public void update( float deltaTime) {
x += 50 * deltaTime;
if (x > 100)
x = 0;
}
If our game runs at a constant 60FPS, the delta time passed to the method will always be
1 / 60 ~ 0.016 second. In each frame, we therefore advance by 50 × 0.016 ~ 0.83 pixel. At
60FPS, we advance 60 × 0.83 ~ 50 pixels! Let's test this with 30FPS: 50 × 1 / 30 ~ 1.66.
Multiplied by 30FPS, we again move 50 pixels total each second. So, no matter how fast the
device on which our game is running can execute our game, our animation and movement will
always be consistent with actual wall clock time.
If we actually tried this with our preceding code, our Pixmap wouldn't move at all at 60FPS.
This is because of a bug in our code. We'll give you some time to spot it. It's rather subtle, but
a common pitfall in game development. The x member that we use to increase each frame is
actually an integer. Adding 0.83 to an integer will have no effect. To fix this, we simply have to
store x as a float instead of an integer. This also means that we have to add a cast to int when
we call Graphics.drawPixmap() .
Note While floating-point calculations are usually slower on Android than integer operations are,
the impact is mostly negligible, so we can get away with using more costly floating-point arithmetic.
And that is all there is to our game framework. We can directly translate the screens of our
Mr. Nom design to our classes and the interface of the framework. Of course, some implementation
details still require attention, but we'll leave that for a later chapter. For now, you can be mighty
proud of yourself. You kept on reading this chapter to the end and now you are ready to become
a game developer for Android (and other platforms)!
Summary
Some fifty highly condensed and informative pages later, you should have a good idea of
what is involved in creating a game. We checked out some of the most popular genres on
Google Play and drew some conclusions. We designed a complete game from the ground up
using only scissors, a pen, and some paper. Finally, we explored the theoretical basis of game
development, and we even created a set of interfaces and abstract classes that we'll use
throughout this topic to implement our game designs, based on those theoretical concepts.
If you feel like you want to go beyond the basics covered here, then by all means consult the
Web for more information. You are holding all the keywords in your hand. Understanding the
principles is the key to developing stable and well-performing games. With that said, let's
implement our game framework for Android!
 
 
Search WWH ::




Custom Search