Game Development Reference
In-Depth Information
2.6 Game View
As mentioned above, GameView is the main view which performs the basic tasks of drawing
throughout the whole life cycle of the game: game start, game play, game pause, and game
stop, etc. It extends SurfaceView and provides a dedicated drawing surface embedded inside
of a view hierarchy.
SurfaceView
A SurfaceView is responsible for placing its surface at the correct location on the screen.
Table 2.4 describes its public methods that are commonly used in programming.
Methods
Description
draw()
Manually renders this view (and all of its children) to the
given Canvas.
getHolder()
Returns the SurfaceHolder providing access and control
over this SurfaceView's underlying surface.
setVisibility()
Sets the enabled state of this view.
setZOrderMediaOverlay()
Controls whether the surface view's surface is placed on
top of another regular surface view in the window (but still
behind the window itself).
setZOrderOnTop()
Controls whether the surface view's surface is placed on
top of its window.
Table 2.4 SurfaceView's Public Methods
To use the SurfaceView, you need to be aware of some threading semantics:
All SurfaceView and SurfaceHolder.Callback methods will be called from the thread run-
ning the SurfaceView's window (typically the main thread of the application). They thus
need to correctly synchronize with any state that is also touched by the drawing thread.
The drawing thread only touches the underlying Surface while it is valid
between surfaceCreated() and surfaceDestroyed() methods.
The GameView implements the SurfaceHolder.Callback interface to receive
the information about any changes to the surface.
public class GameView extends SurfaceView implements SurfaceHolder.Callback
Search WWH ::




Custom Search