Controls Class
This base class 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.Here, the function Controls::setMouseDX() does the same as engine.controls.setMouseDX().// Get the instance of default engine controls Controls controls = engine.getControls(); controls.setMouseDX(5);
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).
Controls Class
Members
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 - State (one of CONTROLS_STATE_* variables).
Return value
1 if the player is in this state, and this function was not called previously in the current frame; otherwise, 0.float getMouseDX ()
Returns a screen position change of the mouse pointer along the X-axis during the last frame (i.e. the delta of mouse movement).Return value
Change of the X-coordinate.float getMouseDY ()
Returns a screen position change of the mouse pointer along the Y-axis during the last frame (i.e. the delta of mouse movement).Return value
Change of the Y-coordinate.int getState (int state)
Checks the state of the given control (pressed or unpressed).Arguments
- int state - State (one of CONTROLS_STATE_* variables).
Return value
1 if the control is pressed; otherwise, 0.string getTypeName ()
Returns a type name of input controls.Return value
Type name.int getType ()
Returns the type of input controls.Return value
Controls type (one of CONTROLS_* variables):void setMouseDX (float delta)
Sets a screen position change of the mouse pointer along the X-axis since the last frame (i.e. updates the delta of mouse movement).Arguments
- float delta - Change of the X-coordinate.
void setMouseDY (float delta)
Sets a screen position change of the mouse pointer along the Y-axis since the last frame (i.e. updates the delta of mouse movement).Arguments
- float delta - Change of the Y-coordinate.
void setState (int state, int mode)
Toggles the state of the given control on or off.Arguments
- int state - State (one of CONTROLS_STATE_* variables).
- int mode - Positive value to "press" the corresponding control; 0 to release it.
int CONTROLS_APP
Description
A ControlsApp instance.int CONTROLS_DUMMY
Description
ControlsDummy instance.int CONTROLS_JOYSTICK
Description
Joystick as the input device.int CONTROLS_NUM_STATES
Description
The total number of controls states.int CONTROLS_SIXAXIS
Description
Sixaxis controller as the input device.int CONTROLS_STATE_AUX_0
Description
Auxiliary state (unreserved) It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_1
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_2
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_3
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_4
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_5
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_6
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_7
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_8
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_9
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_A
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_B
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_C
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_D
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_E
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_AUX_F
Description
Auxiliary state (unreserved). It can be mapped to any control state, if necessary (see the example).int CONTROLS_STATE_BACKWARD
Description
A state in which the player moves backwards.int CONTROLS_STATE_CROUCH
Description
A state in which the player crouches or squats.int CONTROLS_STATE_FIRE
Description
A state in which the player fires their weapon.int CONTROLS_STATE_FORWARD
Description
A state in which the player moves forwards.int CONTROLS_STATE_JUMP
Description
A state in which the player jumps.int CONTROLS_STATE_MOVE_LEFT
Description
A state in which the player moves left.int CONTROLS_STATE_MOVE_RIGHT
Description
A state in which the player moves right.CONTROLS_STATE_RESTORE
Description
A state in which the world is being restored.int CONTROLS_STATE_RUN
Description
A state in which the player runs.int CONTROLS_STATE_SAVE
Description
A state in which the world is being saved.int CONTROLS_STATE_SCREENSHOT
Description
A state in which a screenshot is being taken.int CONTROLS_STATE_TURN_DOWN
Description
A state in which the player turns downward.int CONTROLS_STATE_TURN_LEFT
Description
A state in which the player turns left.int CONTROLS_STATE_TURN_RIGHT
Description
A state in which the player turns right.int CONTROLS_STATE_TURN_UP
Description
A state, in which the player turns upward.int CONTROLS_STATE_USE
Description
A state in which the player utilizes some object.int CONTROLS_XPAD360
Description
XBox 360 game pad as the input device.Last update: 03.07.2017
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter