graphics2d我用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++;
为什么它也会移动枪
# 1 楼答案
在对子弹调用setPosition方法之前,需要克隆枪的position对象