Key Mapping

Get help using Construct 2

Post » Tue Dec 30, 2014 4:25 pm

Good morning, is there a way to map keys easily. For example-

If A is pressed, behave as if X were pressed.
If This area of the screen is touched, behave as if A were pressed.

Thank you.
B
9
S
2
Posts: 56
Reputation: 668

Post » Tue Dec 30, 2014 8:36 pm

Not sure what you're trying to do exactly, but it seems a simple OR block would solve your problem:

If Key A is Pressed
OR
If Key X is Pressed > Do whatever you want it to do.
OR
If this Are is touched
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
20
S
6
G
3
Posts: 637
Reputation: 3,776

Post » Tue Dec 30, 2014 10:41 pm

@brunopalermo Key mapping is a bit more complex then that. For example if you want to let your players change the default controls etc. If anyone has some good examples I would like to see them as well.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Tue Dec 30, 2014 11:17 pm

You are correct, an Or block each time would work.
However I have created an entire complex game with keyboard controls, and now want to map touch screen and gamepad controls.
I'm just hoping it will be easier than making dozens of Or blocks...
B
9
S
2
Posts: 56
Reputation: 668

Post » Wed Dec 31, 2014 1:11 am

You need to use key codes

I'm not sure what the key codes for each button is, but you can set the text or textbox to show the pressed button's key code. I have done this before.

Textbox: Set text to Keyboard.LastKeyCode

The string expression of key code is Keyboard.StringFromKeyCode(Key code number value)

As for key mapping, you need to save the key codes into variables (global vars). Set the default values to default control buttons, then change the values of variables if the player changes the controls.

Oh, I was only talking about keyboard, not sure how key mapping works in touch.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Wed Dec 31, 2014 1:29 am

I did this in one of my projects. It's more difficult than you'd think.

My approach was similar to what sgn15 is suggesting. Of course, there are no 'mouse codes', so that consisted of checking each mouse button per tick, logging whether it was depressed or not, then using a function to activate the control mapped to the chosen button.

If I was doing it again, I think I would migrate some of my global vars (keycodes, control states) into a global dictionary.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Wed Dec 31, 2014 2:44 am

if you want to detect a double tap or combo (like down-right-left combo), reset your textbox every half second (your press and combo presses are quicker than half second anyway) and delete textbox content every half second.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Wed Dec 31, 2014 2:57 am

What I did was made each input button add to a variable constantly as it's being pressed and test the variables instead of the control button presses. Like 0 = not pressed, 1 = just pressed, > 1 = holding the button down.
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Wed Dec 31, 2014 5:23 pm

I think I'll do as corlenbelspar suggests. It'll still be a lot of backwards engineering but it seems the most suitable for my level of competence.
B
9
S
2
Posts: 56
Reputation: 668

Post » Mon Jan 05, 2015 1:02 pm

I understand key mapping well @Burvey, but he didn't ask about that. lol

As I said before, I'm not sure what exactly you're trying to achieve and I have no idea how your capx goes, but for what I have read here, it'd appear that @corlenbelspar 's approach would work fine for you, @danielbishop56.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
20
S
6
G
3
Posts: 637
Reputation: 3,776

Next

Return to How do I....?

Who is online

Users browsing this forum: DiegoSanudoDT and 11 guests