kenman345's Avatar
kenman345 4
27 Asked
63 Answered
13 Best
0
No one has voted on this question yet :(
3 years ago

In processing, how does one de-activate keypresses from effecting what happens.

I am a high school student and I am writing a game in Processing for my class final project. I have two controllable characters but i want them to take turns moving and attacking. for this reason, i need to de-activate all keypresses that are not the ones a player needs to take his turn. Currently, if player 1 is going, if someone were to hit any button on a keyboard besides the ones to control the character, it temporarily causes the player to stop moving until they press another button that controls their character.

I've looked all over the processing website and I cannot figure this out.
Tip for best answer: M$2.00
Separate topics with commas, or by pressing return. Use the delete or backspace key to edit or remove existing topics.

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

What is Your Answer?

0
0
0

2 Answers

0
dudemanguy's Avatar
dudemanguy | 3 years ago
3
Not that I'm an expert programmer or anything, but if it were C++, I bet you could set a global variable to toggle whose turn it is. I *think* you could even replace line 2 of wdawe's with another variable to capture the keyPressed. Then you could make the remaining if statement more specific. If I'm right, which I might not be, it would look something like this:

void draw(){
char key = keyPressed;
if ((key == 'b' && player == 1)||(key == 'B' && player == 1)){
fill(0);
rect(25, 25, 50, 50);
}
}

Duplicate this for the other player to trigger only on their turn.
source(s):
I just learning to program

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel
0
wdawe's Avatar
wdawe | 3 years ago
8
I'm not a processing programmer but what you need to do is to handle the keypress and basically throw it away and continue with your program. If you posted the part of your program that handled keys it would make it easier to help you.

This function only reacts to the letter B or b, everything else is ignored.
void draw() {
if(keyPressed) {
if (key == 'b' || key == 'B') {
fill(0);
rect(25, 25, 50, 50);
}
}
}

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel

Learn something new with our FREE educational apps!

Private lessons in the comfort of your own home. Get back in shape or finally pick up a guitar with our great experts guiding you the whole way!
Learn Guitar
Learn Hip Hop
Learn Pilates