Game Development Reference
In-Depth Information
Texture bobTexture;
Vertices bobModel;
Bob[] bobs;
Our BobScreen class holds a Texture (loaded from bobrbg888.png ), a Vertices instance holding
the model of Bob (a simple textured rectangle), and an array of Bob instances. We also define a
little constant named NUM_BOBS so that we can modify the number of Bobs we want to have on
the screen.
public BobScreen(Game game) {
super (game);
glGraphics = ((GLGame)game).getGLGraphics();
bobTexture = new Texture((GLGame)game, "bobrgb888.png");
bobModel = new Vertices(glGraphics, 4, 12, false , true );
bobModel.setVertices( new float [] { −16, -16, 0, 1,
16, -16, 1, 1,
16, 16, 1, 0,
-16, 16, 0, 0, }, 0, 16);
bobModel.setIndices( new short [] {0, 1, 2, 2, 3, 0}, 0, 6);
bobs = new Bob[100];
for ( int i = 0; i < 100; i++) {
bobs[i] = new Bob();
}
}
The constructor just loads the texture, creates the model, and instantiates NUM_BOBS Bob
instances.
@Override
public void update( float deltaTime) {
game.getInput().getTouchEvents();
game.getInput().getKeyEvents();
for ( int i = 0; i < NUM_BOBS ; i++) {
bobs[i].update(deltaTime);
}
}
The update() method is where we let our Bob instances update themselves. We also make sure
our input event buffers are emptied.
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClearColor(1,0,0,1);
gl.glClear(GL10. GL_COLOR_BUFFER_BIT );
gl.glMatrixMode(GL10. GL_PROJECTION );
Search WWH ::




Custom Search