Game Development Reference
In-Depth Information
orthoCam.update();
spriteBatch.setProjectionMatrix(orthoCam.combined);
spriteBatch.begin();
stringBuilder.setLength(0);
stringBuilder.append("FPS: " +
Gdx.graphics.getFramesPerSecond()).append("\n") ;
stringBuilder.append("Cars: " + count).append("\n");
stringBuilder.append("Total: " + instances.size).append("\n");
font.drawMultiLine(spriteBatch, stringBuilder, 0,
Gdx.graphics.getHeight());
spriteBatch.end();
}
Here, we add an orthographic camera to view 2D items in a 3D scene. Then, we print
the FPS and total number of instances on the top-left corner of the game scene, as
shown in the following screenshot:
Want some 2D in 3D?
In your 3D game, you might want to add some 2D images such as a score
icon or play/pause or mute button or maybe a permanent background
image in the scene. We can use the orthographic camera and sprite batch
to render 2D objects in the scene, just like we rendered the text here.
Now, we can see that there are a number of cars rendering and the total cars
available are 12, even after navigating the scene using the mouse or keys. Hence,
regardless of where the camera is at the moment, the number of instances rendered
in the scene stays 12. Now, it is time to implement frustum culling.
 
Search WWH ::




Custom Search