Unigine::Controls Class
Header: | #include <UnigineControls.h> |
Handles input from the user (keyboard, mouse, joystick or gamepad). It can be used instead of the default engine.controls in one of the two possible ways:
- In case you need custom input handling (by AI, for example), you can implement your own controls via ControlsDummy.
-
You can get the current application controls (i.e. the instance of the default engine controls) via engine.getControls(). After that, you control user input using methods of Controls class exactly the same way as via engine.controls functions.
Such approach, for example, allows to switch between user-controlled input (Controls) and AI-controlled input (ControlsDummy) without having to change the game logic.
// Get the instance of default engine controls Controls controls = engine.getControls(); controls.setMouseDX(5);
Here, the function Controls::setMouseDX() does the same as engine.controls.setMouseDX().
The following set of functions is used to register actions (i.e. controls states) that will be executed on the provided input and bind them to specified input events. The actual meaning of all controls registered with CONTROLS_STATE_* variables (for example, CONTROLS_STATE_JUMP or CONTROLS_STATE_FIRE) is defined manually in script by the programmer who uses them. (See how to map controls states and keys).
See Also#
- The Creating a Car with Suspension Joints usage example demonstrating how to set control keys
Controls Class
Enums
TYPE#
Name | Description |
---|---|
CONTROLS_APP = 0 | A ControlsApp instance. |
CONTROLS_DUMMY = 1 | ControlsDummy instance. |
CONTROLS_SIX_AXIS = 2 | Sixaxis controller as the input device. |
CONTROLS_X_PAD360 = 3 | XBox 360 game pad as the input device. |
CONTROLS_JOYSTICK = 4 | Joystick as the input device. |
Members
static ControlsPtr create ( int type ) #
Creates a smart pointer to Controls.Arguments
- int type - Type of the controls to be created.
void setMouseDX ( float mousedx ) #
Updates a screen position change of the mouse pointer along the X axis.Arguments
- float mousedx - Change of the X coordinate.
float getMouseDX ( ) #
Returns a screen position change of the mouse pointer along the X axis during the previous frame.Return value
Change of the X coordinate.void setMouseDY ( float mousedy ) #
Updates a screen position change of the mouse pointer along the Y axis.Arguments
- float mousedy - Change of the Y coordinate.
float getMouseDY ( ) #
Returns a screen position change of the mouse pointer along the Y axis during the previous frame.Return value
Change of the Y coordinate.void setState ( int state, int value ) #
Toggles the state of the given control on or off.Arguments
- int state - Control state number to update. Possible values are in range [STATE_FORWARD;NUM_STATES]. For full list of available controls see Unigine::Controls:: Enumeration at the end of the article.
- int value - State value: positive value to "press" the control; 0 to release it.
int getState ( int state ) #
Returns the state of a given control (pressed or unpressed).Arguments
- int state - Control state number. Possible values are in range [STATE_FORWARD;NUM_STATES]. For full list of available controls see Unigine::Controls:: Enumeration at the end of the article.
Return value
1 if the control is pressed; otherwise, 0.int getType ( ) #
Returns the type of input controls.Return value
Controls type (one of CONTROLS_* variables):const char * getTypeName ( ) #
Returns a type name of input controls.Return value
Type name.int clearState ( int state ) #
Returns a control state and clears it to 0 (not pressed). This function allows to handle control only once even if it is kept pressed over several frames.Arguments
- int state - Control state number. Possible values are in range [STATE_FORWARD;NUM_STATES]. For full list of available controls see Unigine::Controls:: Enumeration at the end of the article.
Return value
Returns the state of the given control: 1 if the control is pressed; otherwise,0.int restoreState ( const Ptr<Stream> & stream ) #
Restores controls settings from the stream.Arguments
- const Ptr<Stream> & stream - Stream smart pointer.
Return value
1 if the controls settings are restored successfully; otherwise, 0.int saveState ( const Ptr<Stream> & stream ) #
Saves controls settings into the stream.Arguments
- const Ptr<Stream> & stream - Stream smart pointer.