好吧,我用Java制作了这款游戏,当您发射子弹时,它会移动枪支和子弹。这是我认为问题所在的代码块:

case KeyEvent.VK_SPACE:
        Point2D currentGunPos = sGun.position();
        sBullet[bulletNum].setAlive(true);
        sBullet[bulletNum].setPosition(sGun.position());
        sBullet[bulletNum].setVelocity(new Point2D(-5,0));
        bulletNum++;


为什么还要移动枪?

最佳答案

在子弹上调用setPosition方法之前,您需要克隆枪的位置对象。

Point2D currentGunPos = (Point2D)sGun.position().clone();
sBullet[bulletNum].setPosition(currentGunPos);

10-08 01:10