Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Character key names and disabling keys

Author
Message
Gracus
12
Years of Service
User Offline
Joined: 10th Dec 2011
Location:
Posted: 25th Jan 2012 20:30
Hello, trying to do the basics of getting my sprite to run properly.

When I move my character; For example - Left the User can still press any other key which involves multiple sprite animations occurring.

What I want to do is:-

When the User holds down the Left Arrow key, disable Right arrow key.

Another problem I'm having is the character names. I know Spacekey() and the arrow keys, but I can't find any information on the letters and numbers.

Thanks for helping!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 25th Jan 2012 21:03
On my iPad ATM.

Quote: "When I move my character; For example - Left the User can still press any other key which involves multiple sprite animations occurring."

As they can both be equal to 1 at the same time, you'll have to find a way of working out which one was pressed first and to somehow 'disable' the other. I'm not going to simply hand over the exact code you need but more or less put you on the right track.

Depending on how you want this to work, you can make use of checking for two conditions instead of one. E.g


You may even have to create some extra variables e.g left_key_allowed to enable and disable the keys. How do you use them? I'll let you have a go at working this out first. Get those brain cells going.

Quote: "Another problem I'm having is the character names. I know Spacekey() and the arrow keys, but I can't find any information on the letters and numbers."

Pretty straight forward answer for this one. Look into key states (there is even a key state helper in the latest IDE).

Gracus
12
Years of Service
User Offline
Joined: 10th Dec 2011
Location:
Posted: 26th Jan 2012 16:39
Sorry I took long to reply, in college now so I can test it, found the keystates and how to disable keys. Big thanks to you Hodgey

P.S Thanks for not giving the code out and pushing me in the right direction, makes me understand a lot about manipulating the code
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 29th Jan 2012 06:30
I use an "overall movement" variable. XMovement starts at 0, and YMovement starts at 0. Check the keystate of LEFTKEY() and if it's 1, subtract 1 from XMovement. Then check the keystate of RIGHTKEY() and add 1 to XMovement if it's true. Repeat logically for YMovement and UPKEY()/DOWNKEY().

Once you've checked all the keystates, check the values of XMovement and YMovement. If XMovement is 1, move your character to the right. If it's -1, move character left.

The key to this system is that if the user is currently holding down both the left and right arrow keys, the net result of XMovement will be 0, and your character won't move.

Hodgey's method works just fine as well - this is just another angle from which to approach. I like to encourage the consideration of alternate techniques to achieve the same purpose, it broadens people's logical acuity.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 29th Jan 2012 08:33
Quote: "Sorry I took long to reply"

And sorry for my long reply.

Quote: "P.S Thanks for not giving the code out and pushing me in the right direction, makes me understand a lot about manipulating the code"

You're welcome, I'm glad you took it so warmingly.

Login to post a reply

Server time is: 2024-11-22 06:15:14
Your offset time is: 2024-11-22 06:15:14