Unigine::ControlsDummy Class
Header: | #include <UnigineControls.h> |
Inherits from: | Controls |
This class is used to create controls for players that should not be controlled by the user (for example, when such a player is controlled by an AI). This class allows to create any other completely custom implementation of controls.
The code below shows how to create custom controls and toggle showing the item inventory when 'i' key is pressed on the keyboard. For that, auxiliary state STATE_AUX_0 is used.
#include <UnigineApp.h>
using namespace Unigine;
// ...
ControlsDummyPtr my_controls = ControlsDummy::create(); // custom controls
bool inventory_toggled = false; // show item inventory toggle
void update_input(ControlsPtr controls) {
// Check if the key is pressed and update the state of the specified control.
// You can use both 'i' or ASCII code (105).
controls->setState(Controls::STATE_AUX_0, App::getKeyState('i'));
}
// Implement your game logic for showing or hiding item inventory.
void update_game_logic(ControlsPtr controls) {
// If the control state is positive (the key has been pressed), toggle item
// inventory on and off.
if (controls->getState(Controls::STATE_AUX_0)) {
inventory_toggled = !inventory_toggled;
}
}
/*
*/
// Update controls each frame according to the user input.
int AppWorldLogic::update() {
update_input(my_controls);
update_game_logic(my_controls);
}
ControlsDummy Class
Members
static ControlsDummyPtr create ( ) #
Constructor. Creates a new set of dummy controls.Last update:
10.03.2022
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter