Game Development Reference
In-Depth Information
stick to the approach used in Mr. Nom: static text will be prerendered as a
whole, and only dynamic text (for example, numbers in high scores) will be
rendered via an atlas.
You might have noticed that Bobs disappear before they are graphically hit by the cannonball.
This is because our bounding shapes are a little too big. We have some white space around Bob
and the cannonball. What's the solution? Just make the bounding shapes a little smaller. You
should get a feel for this, so manipulate the source until the collision feels right. You will often
find such fine-tuning “opportunities� while developing a game. Fine tuning is probably one of
the most crucial parts of game development, aside from good level design. Getting things to
feel right can be hard, but it is highly satisfactory once you have achieved the level of
perfection found in Super Mario Brothers . Sadly, this is nothing that can be taught, as it is
dependent on the look and feel of your game. Consider it the magic sauce that sets good
and bad games apart.
Note To handle the disappearance issue just mentioned, make the bounding rectangles a little
smaller than their graphical representations to allow for some overlap before a collision is triggered.
Texture Regions, Sprites, and Batches: Hiding OpenGL ES
Our code so far, for the cannon example, is made up of a lot of boilerplate, some of which can
be reduced. One such area is the definition of the Vertices instances. It's tedious to have seven
lines of code just to define a single textured rectangle. Another area we could improve is the
manual calculation of texture coordinates for images in a texture atlas. Finally, there's a lot of
highly repetitive code involved when we want to render our 2D rectangles. There is also a better
way of rendering many objects than to have one draw call per object. We can solve all these
issues by incorporating a few new concepts:
ï?® Texture regions : We worked with texture regions in the last example. A
texture region is a rectangular area within a single texture (for example, the
area that contains the cannon in our atlas). We want a nice class that can
encapsulate all the nasty calculations for translating pixel coordinates to
texture coordinates.
ï?® Sprites : A sprite is a lot like a game object. It has a position (and possibly
orientation and scale), as well as a graphical extent. You render a sprite via
a rectangle, just as you render Bob or the cannon. In fact, the graphical
representations of Bob and the other objects can and should be considered
sprites. A sprite also maps to a region in a texture. That's where texture
regions come in. While it is tempting to combine sprites and game objects
in the game directly, you should keep them separated, following the Model-
View-Controller pattern. This clean separation between graphics and model
code makes for a better design.
ï?® Sprite batchers : A sprite batcher is responsible for rendering multiple
sprites in one go. To do this, the sprite batcher needs to know each sprite's
 
 
Search WWH ::




Custom Search