pong

Pong Controls With KeyListener

為{幸葍}努か 提交于 2019-11-30 09:37:22
问题 I have ran into a bit of trouble getting my pong game to work, this project started simply with making a ball have physics but then i decided to do some more work I have that ball bounce back and forth and all but the keys W and S wont control player one and the up and down arrow keys dont control player 2 public void keyPressed(KeyEvent e){ if(e.getKeyCode() == e.VK_UP){ p2Y -= 3; System.out.println("UP"); } if(e.getKeyCode() == e.VK_DOWN){ p2Y += 3; System.out.println("Down"); } if(e

Pong Controls With KeyListener

别来无恙 提交于 2019-11-29 16:08:16
I have ran into a bit of trouble getting my pong game to work, this project started simply with making a ball have physics but then i decided to do some more work I have that ball bounce back and forth and all but the keys W and S wont control player one and the up and down arrow keys dont control player 2 public void keyPressed(KeyEvent e){ if(e.getKeyCode() == e.VK_UP){ p2Y -= 3; System.out.println("UP"); } if(e.getKeyCode() == e.VK_DOWN){ p2Y += 3; System.out.println("Down"); } if(e.getKeyCode() == e.VK_W){ p1Y -= 3; System.out.println("Up"); } if(e.getKeyCode() == e.VK_S){ p1Y += 3; System

How Do I Use KeyEventDispatcher

好久不见. 提交于 2019-11-26 00:09:15
问题 I have been trying to make a Pong clone as sort of a beginner\'s project, and I\'ve hit a road block. I have managed to get to the point of keyboard support, but the keyboard repeat delay kicks in. I haven\'t found any usable way to use KeyEventDispatcher. It won\'t even initiate the dispatchKeyEvent() method. How would I go about using this? Thanks in advance. PS: Here is my source so far: http://pastebin.com/N9fLMzFT 回答1: you have to look for KeyBindings import java.awt.*; import java.awt