This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
en:guides:beginners:input_controls [2021/07/14 22:57 (4 years ago)] – iarwain | en:guides:beginners:input_controls [2024/11/18 03:28 (7 months ago)] (current) – Highlights sausage | ||
---|---|---|---|
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 [Input] section, which is used as the default input set. | + | 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: | ||
- | < | + | < |
[Input] | [Input] | ||
KEY_ESCAPE | KEY_ESCAPE | ||
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 Update() function to detect these keys. The Update() 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 '' |
< | < | ||
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 |