Game Development Reference
In-Depth Information
cannon = new Cannon(0, 0, 1, 0.5f);
Since we don't do any collision detection with the cannon itself, it doesn't really matter what size
we set in that constructor; we just do it for consistency.
The last thing we need to change is our render method. Here it is in its full glory:
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.setViewportAndMatrices();
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL10.GL_TEXTURE_2D);
texture.bind();
targetVertices.bind();
int len = targets.size();
for ( int i = 0; i < len; i++) {
GameObject target = targets.get(i);
gl.glLoadIdentity();
gl.glTranslatef(target.position.x, target.position.y, 0);
targetVertices.draw(GL10.GL_TRIANGLES, 0, 6);
}
targetVertices.unbind();
gl.glLoadIdentity();
gl.glTranslatef(ball.position.x, ball.position.y, 0);
ballVertices.bind();
ballVertices.draw(GL10.GL_TRIANGLES, 0, 6);
ballVertices.unbind();
gl.glLoadIdentity();
gl.glTranslatef(cannon.position.x, cannon.position.y, 0);
gl.glRotatef(cannon.angle, 0, 0, 1);
cannonVertices.bind();
cannonVertices.draw(GL10.GL_TRIANGLES, 0, 6);
cannonVertices.unbind();
}
Here, we enable blending, set a proper blending function, enable texturing, and bind our atlas
texture. We also slightly adapt the cannonVertices.draw() call, which now renders two triangles
instead of one. That's all there is to it. Figure 8-24 shows the results of our face-lifting operation.
 
Search WWH ::




Custom Search