Customizing keyboard/joypad controls ingame?

Get help using Construct 2

Post » Sat Feb 22, 2014 4:32 pm

Where can I find a tutorial about customizing keyboard/joypad controls ingame?
B
5
Posts: 40
Reputation: 307

Post » Sat Feb 22, 2014 8:49 pm

I didn't find a tutorial for you, so I made a commented example.
Here it is.

I did custom control for only 4 controls (up, right left and down) as it is exactly the same for others and that would have made the code harder to read.
The thing is cut in 2 layouts. One is for the options, where the user will set the controls. The other one is for the game, but I only put a display in it.
If you go in the options, click on a text box and then put an input using keyboard or gamepad, it should display in the box. Returning to the Display layout and inputing the same key should display that the key is recognised, and where it came from.

To use it in a game, I separated 4 functions in the "Display" event sheet. Those 4 functions are respectively called by the 4 inputs, after all the custumization the user did. So if you had movements to map, or jump, everything can be put in there.

As for the method I used :
- An array "Control" will store the user settings : Controls.At(ControlDirection,InputMethod) = UserKey
- the ExecuteKey function handles every input given by the user, and calls the corresponding function if it was a mapped key.

For more details, the code is commented.

For even more details, just ask :)
B
17
S
8
G
4
Posts: 461
Reputation: 6,147

Post » Sat Feb 22, 2014 9:02 pm

Guizmus wrote:I didn't find a tutorial for you, so I made a commented example.
Here it is.

I did custom control for only 4 controls (up, right left and down) as it is exactly the same for others and that would have made the code harder to read.
The thing is cut in 2 layouts. One is for the options, where the user will set the controls. The other one is for the game, but I only put a display in it.
If you go in the options, click on a text box and then put an input using keyboard or gamepad, it should display in the box. Returning to the Display layout and inputing the same key should display that the key is recognised, and where it came from.

To use it in a game, I separated 4 functions in the "Display" event sheet. Those 4 functions are respectively called by the 4 inputs, after all the custumization the user did. So if you had movements to map, or jump, everything can be put in there.

As for the method I used :
- An array "Control" will store the user settings : Controls.At(ControlDirection,InputMethod) = UserKey
- the ExecuteKey function handles every input given by the user, and calls the corresponding function if it was a mapped key.

For more details, the code is commented.

For even more details, just ask :)


wow thank you!
B
5
Posts: 40
Reputation: 307


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest