Game Development Reference
In-Depth Information
gl.glEnable(GL10. GL_BLEND );
gl.glPushMatrix();
gl.glTranslatef(position.x, position.y, position.z);
batcher.beginBatch(Assets. explosionTexture );
batcher.drawSprite(0, 0, 2, 2, frame);
batcher.endBatch();
gl.glPopMatrix();
gl.glDisable(GL10. GL_BLEND );
}
}
Finally, we have the mysterious renderExplosion() method. We get the position at which we
want to render the explosion, as well as the state time of the object that is exploding. The latter
is used to fetch the correct TextureRegion from the explosion Animation , just as we did for Bob
in Super Jumper.
The first thing we do is fetch the explosion animation frame based on the state time. Next, we
enable blending, since the explosion has transparent pixels that we don't want to render. We
push the current model-view matrix and call glTranslatef() so that anything we render after
that call will be positioned at the given location. We tell the SpriteBatcher that we are about to
render a rectangle using the explosion texture.
The next call is where the magic happens. We tell the SpriteBatcher to render a rectangle at
(0,0,0) (the z coordinate is not given but implicitly zero, remember?), with a width and height of
2 units. Because we used glTranslatef() , that rectangle will be centered not around the origin,
but rather around the position we specified to glTranslatef() , which is exactly the position of
the ship or invader that exploded. Finally, we pop the model-view matrix and disable blending
again.
That's it. Twelve classes, forming a full 3D game, parroting the classic Space Invaders game. Try
it out. When you come back, we'll have a look at the performance characteristics.
Optimizations
Before we think about optimizing the game, we have to evaluate how well it performs. We
put an FPSCounter in the GameScreen class, so let's look at its output on a Hero, a Droid, and
a Nexus One.
Hero (Android 1.5):
02-17 00:59:04.180: DEBUG/FPSCounter(457): fps: 25
02-17 00:59:05.220: DEBUG/FPSCounter(457): fps: 26
02-17 00:59:06.260: DEBUG/FPSCounter(457): fps: 26
02-17 00:59:07.280: DEBUG/FPSCounter(457): fps: 26
Nexus One (Android 2.2.1):
02-17 01:05:40.679: DEBUG/FPSCounter(577): fps: 41
02-17 01:05:41.699: DEBUG/FPSCounter(577): fps: 41
02-17 01:05:42.729: DEBUG/FPSCounter(577): fps: 41
02-17 01:05:43.729: DEBUG/FPSCounter(577): fps: 40
 
Search WWH ::




Custom Search