| 1 | [[TOC]] |
| 2 | = <lol/input/controller.h> = |
| 3 | |
| 4 | View this file in the source browser: [browser:trunk/src/input/controller.h] |
| 5 | |
| 6 | == Controller == |
| 7 | |
| 8 | The controller is the central hub to manage your input in lolengine. |
| 9 | |
| 10 | There are two way to initialize it: |
| 11 | |
| 12 | - By hand: |
| 13 | {{{ |
| 14 | #!cpp |
| 15 | Controller* my_controller = new Controller("MyName"); |
| 16 | my_controller->SetInputCount(MAX_KEYS, MAX_AXIS); |
| 17 | |
| 18 | my_controller->GetKey(Key0).Bind("Keyboard", "Space"); |
| 19 | my_controller->GetAxis(Axis0).Bind("Mouse", "Y"); |
| 20 | Etc... |
| 21 | }}} |
| 22 | |
| 23 | - More easily, by InputProfile: |
| 24 | {{{ |
| 25 | #!cpp |
| 26 | InputProfile my_profile; |
| 27 | my_profile << InputProfile::Keyboard(key0, key0_name) |
| 28 | << InputProfile::MouseAxis(key1, key1_name) |
| 29 | << InputProfile::JoystickKey(joy1_key0, joy1_nb, joy1_key0_name); |
| 30 | |
| 31 | Controller* my_controller = new Controller("MyName", my_profile); |
| 32 | }}} |
| 33 | |
| 34 | Using the Input profiles allows you to use several profiles by using `Init()` and `ClearProfile()`. |
| 35 | |
| 36 | Please note that Key value must all be unique, even if the device (mouse/keyboard/....) is different. |
| 37 | Same rule applies to axis. |
| 38 | |
| 39 | === Querying the controller === |
| 40 | |
| 41 | To query the input status, use the corresponding methods: |
| 42 | |
| 43 | {{{ |
| 44 | #!cpp |
| 45 | KeyBinding& key = my_controller->GetKey(Key0); |
| 46 | AxisBinding& axis = my_controller->GetAxis(Axis0); |
| 47 | }}} |
| 48 | |
| 49 | And then use the status methods for your usage: |
| 50 | |
| 51 | With keys: |
| 52 | - `IsDown()`: Indicates wheither the key is currently pressed |
| 53 | - `IsUp()`: Indicates wheither the key is currently released |
| 54 | - `JustPressed()`: Indicates wheither the key has just been pressed |
| 55 | - `JustReleased()`: Indicates wheither the key has just been released |
| 56 | |
| 57 | Or axis: |
| 58 | - `GetValue()`: Gets the current absolute value of this axis |
| 59 | - `GetDelta()`: Gets the current delta value of this axis |
| 60 | |
| 61 | |