我有 2 个矩形代表我的 Pong 游戏的桨。我对一个矩形使用 W/S,对第二个矩形使用 UP/DOWN。当我按 W 移动一个矩形,然后按 UP 移动第二个矩形时,第一个矩形将停止移动,然后第二个矩形将移动。如何使两个矩形可以同时移动?
GraphicsContext gc;
Rectangle player11;
Rectangle player22;
Circle ball;
private int y1;
private int p1y = 381;
private int y2;
private int p2y = 381;
AnimateObjects animate;
Canvas canvas;
private AnimationTimer timer = new AnimationTimer() {
public void handle(long now) {
// update paddle positions
p1y += y1;
p2y += y2;
if (p1y < 0) {
p1y = 0;
}
if (p2y < 0) {
p2y = 0;
}
player11.setY(p1y); …Run Code Online (Sandbox Code Playgroud)