User Tools

Site Tools


en:guides:beginners:input_controls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:guides:beginners:input_controls [2018/02/13 20:47 (7 years ago)] – ↷ Page moved from guides:beginners:input_controls to en:guides:beginners:input_controls iarwainen: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 [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 ''[Input]'' sectionwhich is used as the default input set.
  
 Let's add a few more: Let's add a few more:
  
-<code=ini> +<code=ini [highlight_lines_extra="3,4,5,6"]
-[MainInput]+[Input]
 KEY_ESCAPE   = Quit KEY_ESCAPE   = Quit
 KEY_LEFT     = GoLeft KEY_LEFT     = GoLeft
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 ''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:
  
 <code=cpp> <code=cpp>
Line 36: Line 36:
 </code> </code>
  
-And declare the variable at the top under the include orx.h line:+And declare the variable at the top
 + 
 +<code=cpp [highlight_lines_extra="4"]> 
 +#include "orx.h
 +#include "orxExtensions.h"
  
-<code=cpp> 
 orxOBJECT *hero; orxOBJECT *hero;
 </code> </code>
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:
  
-<code=cpp>+<code=cpp [highlight_lines_extra="1,2,6,11"]>
 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:
  
-<code=ini>+<code=ini [highlight_lines_extra="4"]>
 [HeroBody] [HeroBody]
 Dynamic           = true Dynamic           = true
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 ''update()'' function:
  
 <code=ini> <code=ini>
 orxVECTOR jumpSpeed = { 0, -600, 0 }; orxVECTOR jumpSpeed = { 0, -600, 0 };
  
-if (orxInput_IsActive("Jump") && orxInput_HasNewStatus("Jump"))+if (orxInput_HasBeenActivated("Jump"))
 { {
     orxObject_ApplyImpulse(hero, &jumpSpeed, orxNULL);     orxObject_ApplyImpulse(hero, &jumpSpeed, orxNULL);
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:
  
-<code=ini>+<code=ini [highlight_lines_extra="5"]>
 [HeroBody] [HeroBody]
 Dynamic           = true Dynamic           = true
Line 103: Line 106:
 ---- ----
  
-Next: [[guides:beginners:running_and_standing|Part 11 – Running and Standing]].+Next: [[en:guides:beginners:running_and_standing|Part 11 – Running and Standing]].
  
-{{section>guides:beginners:toc&noheader&nofooter&noeditbutton}}+{{section>en:guides:beginners:toc&noheader&nofooter&noeditbutton}}
en/guides/beginners/input_controls.1518583671.txt.gz · Last modified: 2018/02/14 00:47 (7 years ago) (external edit)