I'm having an issue with some code I'm just playing around with. Imagine a top down space shooter. The issue I'm having is that, on my computer, when I press and hold the up and left arrows, I cannot shoot (Spacebar). Any other direction (up, down, left, right, up + right, right + down, left + down) works. I had a friend run the code on his computer and he found that all directions worked except up + right and right + down, but up + left worked fine for him. We both looked at the code and can't figure it out. Could this be a hardware issue?
Timer timer = new Timer(250, new ActionListener()
public void actionPerformed(ActionEvent e)
fire = false;
Also, you are missing a bracket and ; on line 109 I think it is, they are actually on line 119, dunno if that's just an upload error or if it's coded like that.
Joined: Mar 01, 2011
tom klu wrote:well, i think you should try this:
i use a whole different method , but i prefer this one
post this in your keypressed method be sure to make it KeyEvent e
be sure to copy this code also in the keyreleased, set the booleans to false.
you might ask UP,DOWN,LEFT,RIGHT?
just add this in your script:
I tried your code but I still had the same issue. What's the preferred method to handle this in games? Surely there must be a solution.
Joined: Mar 04, 2011
well you might try making booleans..... this will def. work or otherwise it must be your keyboard.
Joined: Mar 01, 2011
Stephan van Hulst wrote:Yes, I believe it's actually a keyboard limitation. Try running on the same computer with a different keyboard.
I did try a different keyboard but had the same results. The same key combination did not work.
tom klu wrote:well you might try making booleans..... this will def. work or otherwise it must be your keyboard.
I downloaded a top down space shooter programmed in Java and had no issues moving up and left and firing. However, movement used WASD instead of the arrow keys - as does your code above. It now works using WASD so it must be an issue with using the arrow keys and spacebar at the same time.