Game Development Reference
In-Depth Information
How it works...
The
AppState
object listens for the input from the player via
InputManager
and ap-
plies it to the application's camera. In just one short class, we've produced an RTS-like
camera behavior.
Lastly, in this recipe, we added functionalities to pan the camera if the mouse cursor was
near the edges of the screen. We used
InputManager.getCursorPosition()
,
which is a very convenient method that returns the position of the mouse in the screen
space. The bottom-left part of the screen has an x,y coordinate of 0,0. The top-left part of
the screen has an
x
,
y
coordinate that is the same as the height and width of the screen in
pixels. The next
if
statements check whether the cursor is in the 10 percent of the outer-
most portion of the camera (which in this case is the same as the screen) and modify
tem-
pVector
accordingly.