Game Development Reference
In-Depth Information
Controlling shapes
One way to make shapes move is by using event handling. We start moving the object
when the player clicks on a key, and we can stop moving the object when that key is re-
leased. Here is the screenshot of a code example:
The moving variable determines if we should move our object in the current frame. That
variable's value is changed when we press or release the Right Arrow Key . However, that is
a lot of code for essentially very little information—"is the Right Arrow Key currently
pressed?" Fortunately for us, SFML provides a very simple interface to check the current
state of the input devices (keyboard, mouse, and all joysticks).
Checking the state of a key is no harder than calling a single static function— Key-
board::isKeyPressed() . When we pass a key value as an argument, we get the
status of whether that key is currently pressed. However, this function doesn't take into ac-
Search WWH ::




Custom Search