Need help with Keydown Control

Talk about making games.

Need help with Keydown Control

Postby sillydraco » Thu Jun 03, 2010 7:06 am

I have a quick question, i added a climbing feature to my game. i made it so that if my character was between the edges of a vine wall (i made three actors, the left border, middle vine wall, and the right border) and whenever you keydown "up" he will climb. everything works fine until you keydown two arrowkeys at the same time. then things fall out of whack (namely the character falls off the wall) how do i keep the player from messing things up by keydowning too many arrowkeys? i tried using variables (up down left and right) and setting it so that whenever one key is pressed (if the variable for that arrow == 1) it sets the other variables to 0. then on the keyup it would set all of them back to 1. it still doesnt work though :(

for some reason, my drag and drop upload box doesnt work :(
http://scalesnfuzz.com/Levels.zip
Attachments
screeny.png
Time for sleepy, dream of new things...new life, new reality, new wings.
Image
User avatar
sillydraco
 
Posts: 71
Joined: Fri Apr 03, 2009 7:54 am
Score: 3 Give a positive score

Re: Need help with Keydown Control

Postby Chai » Thu Jun 10, 2010 4:26 am

Actually if you press two key at the same time, Those key will work at the same time.
So the code will minus itself.

example:
Key Up : y -= 5;
Key Down : y += 5;

when you press both of it Y will be 0;

Normally when People play the game.
It is really rarely to find a player who press opposite direction button at the same time.
So I think you no need to worry about it.
User avatar
Chai
 
Posts: 361
Joined: Sat Apr 30, 2005 2:26 pm
Location: Thailand
Score: 30 Give a positive score

Re: Need help with Keydown Control

Postby DST » Fri Jun 11, 2010 4:20 pm

Good point, on a controller, you can't hit left and right at the same time.

But if you want to keep only one key active, just use a global variable, and assign each key a number. That way, you don't have to reset the others, the global variable will always hold the value of the last key pressed.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Need help with Keydown Control

Postby sillydraco » Tue Jul 06, 2010 6:06 pm

huh guess i shoulda thought of that x3 i mainly didnt want people pressing up and left at the same time, it confuses the code and makes you fall off the wall x3
Time for sleepy, dream of new things...new life, new reality, new wings.
Image
User avatar
sillydraco
 
Posts: 71
Joined: Fri Apr 03, 2009 7:54 am
Score: 3 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest