Game Development Reference
In-Depth Information
Chapter 8
2D Game Programming Tricks
Chapter 7 demonstrated that OpenGL ES offers quite a lot of features to exploit for 2D graphics
programming, such as easy rotation and scaling and the automatic stretching of your view
frustum to the viewport. It also offers performance benefits over using the Canvas .
Now it's time to look at some of the more advanced topics of 2D game programming. You used
some of these concepts intuitively when you wrote Mr. Nom, including time-based state updates
and image atlases. A lot of what's to come is also indeed very intuitive, and chances are high
that you'd have come up with the same solution sooner or later. But it doesn't hurt to learn about
these things explicitly.
There are a handful of crucial concepts for 2D game programming. Some of them will be
graphics related, and others will deal with how you represent and simulate your game world. All
of these have one thing in common: they rely on a little linear algebra and trigonometry. Fear not,
the level of math needed to write games like Super Mario Brothers is not exactly mind blowing.
Let's begin by reviewing some concepts of 2D linear algebra and trigonometry.
Before We Begin
As with the previous “theoretical� chapters, we are going to create a couple of examples to get
a feel for what's happening. For this chapter, we can reuse what we developed in Chapter 7,
mainly the GLGame , GLGraphics , Texture , and Vertices classes, along with the rest of the
framework classes.
Set up a new project in the exact same way you set up the project in Chapter 7. Copy over the
com.badlogic.androidgames.framework package to your new project, and then create a new
package called com.badlogic.androidgames.gamedev2d .
Add a starter class called GameDev2DStarter . Reuse the code of GLBasicsStarter and simply
replace the class names of the tests. Modify the manifest file so that this new starter class will
be launched. For each of the tests we are going to develop, you have to add an entry to the
manifest in the form of <activity> elements.
355
 
Search WWH ::




Custom Search