Mouse
Query button states
Querying button states is done using cer::isMouseButtonDown()
and cer::isMouseButtonUp()
.
Query mouse position
Obtaining the mouse cursor’s current position is done via cer::currentMousePosition()
.
Sometimes, you might be interested in how much the mouse has traveled between the previous and current frame. You could keep track of the current and previous mouse position, and calculate their difference.
This functionality is built into cerlib via cer::currentMousePositionDelta()
.
Lock the mouse cursor
To lock the mouse cursor into the game’s window, call the Window::setMouseGrab()
method:
This will ensure that the mouse always stays within the window’s area. Such a behavior is desired in games that provide some form of aiming, such as shooters.
To release the mouse cursor again, pass false
to the method:
DPI awareness
The mouse position must be multiplied by the window’s pixel ratio, in case the window’s display is a high DPI display. This is necessary because the mouse position is expressed in logical display units, not pixels. Multiplying it with the pixel ratio converts it to pixel space, which is what cerlib’s rendering uses. If you don’t intent to support high DPI displays in your game, you don’t have to take the pixel ratio into account and can leave the multiplication out.
Mouse events
Note
This assumes that you’ve read Events.
The following events are related to the keyboard:
MouseButtonPressEvent
: Raised when a key was pressed.MouseButtonReleaseEvent
: Raised when a key was released.MouseDoubleClickEvent
: Raised when a double click was performed.MouseWheelEvent
: Raised when the mouse wheel was scrolled.