• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] Keyboard and mouse bug..

This topic is 5147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a strange bug.. I have made this space invaders game, but I have one bug I just cannot get rid off.. first, this is how I do my input routines: every time my plane is in the "enter" state, I reset the input by removing and then adding the handelers again.. what happens is: if I´m holding a key down while I die or go to the next level, all inputs are just locked, and I have to close the game and restart it.. its just 2 much code to upload, so I just hope this is a very typical mistake that every one know of exept me, hehe Hans-Petter Harveg

Share this post


Link to post
Share on other sites
Advertisement
Instead of unloading the handlers, try using a boolean to shut them off. Like this:

public void keyPressed(KeyEvent e) {
if(keysEnabled) {
int key = e.getKeyCode();
if(key == KeyEvent.VK_UP) {
//go up

}
//etc etc

}
}




First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites
thanks alot! but, hmm, i think i wanna rewrite alot here, its really bad written (my frist real java project so.. )

How can I (if possible) controll a variable in "SpaceInvader" class from my "player" class?? (I need to be able to control some of the game stated from the "SpaceInvader" class??


Hans-Petter

[edited by - sushi-one on January 16, 2004 10:30:15 AM]

Share this post


Link to post
Share on other sites

  • Advertisement