Game Development Reference
In-Depth Information
camera.position.set(0, 0, 0);
camera.update();
cameraGUI = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH,
Constants.VIEWPORT_GUI_HEIGHT);
cameraGUI.position.set(0, 0, 0);
cameraGUI.setToOrtho(true); // flip y-axis
cameraGUI.update();
}
public void resize (int width, int height) {
camera.viewportWidth = (Constants.VIEWPORT_HEIGHT
/ (float)height) * (float)width;
camera.update();
cameraGUI.viewportHeight = Constants.VIEWPORT_GUI_HEIGHT;
cameraGUI.viewportWidth = (Constants.VIEWPORT_GUI_HEIGHT
/ (float)height) * (float)width;
cameraGUI.position.set(cameraGUI.viewportWidth / 2,
cameraGUI.viewportHeight / 2, 0);
cameraGUI.update();
}
The added code creates a second camera that is specifically set up just to render
the game's GUI. The viewport of the GUI camera is defined using a different set of
constants that uses much higher values. We have to do this to correctly render the
bitmap font that is 15 pixels high. If we were to use the 5 meters x 5 meters viewport,
only one-third of the font's glyph would be visible at any time. The rest of the added
code does the same as the game camera. Also, this allows us to move the world
camera ( camera ) independently from the GUI ( cameraGUI ).
The following section describes the implementation of the methods for each
GUI element.
The GUI score
The following is a screenshot of the GUI element that shows the player's current score:
 
Search WWH ::




Custom Search