Game Development Reference
In-Depth Information
This method calculates the center of the GUI camera's viewport. The text is rendered
using the big font from our assets. Its color is changed using the
setColor()
method
of
BitmapFont
. The game over text is drawn using the
drawMultiLine()
method of
BitmapFont
, which takes a reference to
SpriteBatch
, the actual text to be displayed,
a 2D position, a horizontal offset, and a constant for horizontal text alignment.
We could have used
draw()
instead of
drawMultiLine()
; however,
draw()
does not provide the horizontal text alignment parameter
that we need to center the text around its 2D position. The text might
contain newlines (
\n
) to display multiline text, which we do not use in
the preceding code.
We are using the
BitmapFont.HAlignment.CENTER
constant to tell
BitmapFont
that we want it to draw the given text horizontally centered to the given position.
The text message
GAME OVER
will only be visible if the
isGameOver()
method of
WorldController
returns
true
.
The following is the screenshot of a case where all the extra lives were used up until
the game was over: