Graphics Programs Reference
In-Depth Information
long deltaTime,startTime,endTime;
startTime = SystemClock.uptimeMillis() % 1000;
gl.glClear(GLES20.GL_COLOR_BUFFER_BIT |
GLES20.GL_DEPTH_BUFFER_BIT);
updateModel(Counter.getUpDownValue(), _zAngle);
renderModel(gl);
endTime = SystemClock.uptimeMillis() % 1000;
deltaTime = Math.abs(endTime - startTime);
if (deltaTime < 20) {
try {
Thread.sleep(20 - deltaTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
frame, which is nothing but the time taken by the method calls
updateModel()
and
renderModel()
. If
deltaTime
is less than 20 milliseconds, the Renderer
thread is blocked for
(20 - deltaTime)
milliseconds. If it is more than that, the
thread is not blocked.
Including Missiles for the Tank
For the
Tank Fence
game, point sprites will be used as missiles. Although we can use
other primitives to represent missiles, using point sprites for this purpose will make
things a lot easier.
Create a new Java class called
Missile
, inside the
src
folder for the
TANK FENCE
GAME 2
application. Because we are using point sprites to represent missiles, the
Missile
object (
Listing 6-9
)
must contain fields to store the x, y, and z coordinates
of the source and destination position of point sprite. For this, create the correspond-
ing fields as shown in
Listing 6-9
.
Search WWH ::

Custom Search