This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:guides:beginners:input_controls [2018/02/14 04:47 (8 years ago)] – ↷ Links adapted because of a move operation iarwain | en:guides:beginners:input_controls [2025/09/30 17:26 (8 weeks ago)] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| Now to add some keyboard control so that our hero is able to jump and run around. | Now to add some keyboard control so that our hero is able to jump and run around. | ||
| - | First we'll need to define some keys. You'll notice that one key (quit) is already defined in the [MainInput] section which is used by the [Input] section. | + | First we'll need to define some keys. You'll notice that one key (quit) is already defined in the '' |
| Let's add a few more: | Let's add a few more: | ||
| - | < | + | < |
| - | [MainInput] | + | [Input] |
| KEY_ESCAPE | KEY_ESCAPE | ||
| KEY_LEFT | KEY_LEFT | ||
| Line 18: | Line 18: | ||
| This assigns labels to keys. These labels can be accessed in the code. | This assigns labels to keys. These labels can be accessed in the code. | ||
| - | You can add code the Run() function to detect these keys. The Run() function is tied to the Orx core clock so the keys can be checked on every frame: | + | You can add code the '' |
| < | < | ||
| Line 36: | Line 36: | ||
| </ | </ | ||
| - | And declare the variable at the top under the include orx.h line: | + | And declare the variable at the top: |
| + | |||
| + | < | ||
| + | #include | ||
| + | #include " | ||
| - | < | ||
| orxOBJECT *hero; | orxOBJECT *hero; | ||
| </ | </ | ||
| Line 44: | Line 47: | ||
| Now it is possible to affect the object in code. We'll add a vector direction as a speed to the object based on the key pressed: | Now it is possible to affect the object in code. We'll add a vector direction as a speed to the object based on the key pressed: | ||
| - | < | + | < |
| orxVECTOR leftSpeed = { -20, 0, 0 }; | orxVECTOR leftSpeed = { -20, 0, 0 }; | ||
| orxVECTOR rightSpeed = { 20, 0, 0 }; | orxVECTOR rightSpeed = { 20, 0, 0 }; | ||
| Line 63: | Line 66: | ||
| He needs some damping on his body to slow him down when a speed is not being applied: | He needs some damping on his body to slow him down when a speed is not being applied: | ||
| - | < | + | < |
| [HeroBody] | [HeroBody] | ||
| Dynamic | Dynamic | ||
| Line 72: | Line 75: | ||
| Run that and our hero will decelerate to a quick stop when no key is pressed. | Run that and our hero will decelerate to a quick stop when no key is pressed. | ||
| - | Next, we can add a jump: | + | Next, we can add a jump to the '' |
| < | < | ||
| orxVECTOR jumpSpeed = { 0, -600, 0 }; | orxVECTOR jumpSpeed = { 0, -600, 0 }; | ||
| - | if (orxInput_IsActive(" | + | if (orxInput_HasBeenActivated(" |
| { | { | ||
| orxObject_ApplyImpulse(hero, | orxObject_ApplyImpulse(hero, | ||
| Line 91: | Line 94: | ||
| Cool he can jump around using the shift key. But our hero turns over when he hits a platform edge. We can fix that by fixing his rotation: | Cool he can jump around using the shift key. But our hero turns over when he hits a platform edge. We can fix that by fixing his rotation: | ||
| - | < | + | < |
| [HeroBody] | [HeroBody] | ||
| Dynamic | Dynamic | ||