对于开始,你能移动
mouseStateCurrent = Mouse.GetState();
if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
{
if (mouseStatePrevious.LeftButton != ButtonState.Pressed)
{
AddProjectile(player.positionPlayer);
mouseStatePrevious = mouseStateCurrent; //<-- This line
}
}
//<-- Here
当您按下按钮,就永远不会进入,如果一次。
编辑1
此外,这在你的弹丸
Player playerObject = new Player();
Game1 gameObject = new Game1();
有看起来像:
Player playerObject;
Game1 gameObject;
public Projectile(Player player, Game1 game)
{
playerObject = player;
gameObject = game;
}
由于您使用的这些只拿到了出发地和目的地子弹,如果你只是在外面计算这些子弹,并且在初始化时通过它们会更好。 (因为它会删除弹丸的需要知道的Game1和球员的对象看起来像)
你也可以完全删除初始化方法,只是用弹的构造函数,这似乎更自然。 (如果你使用这个构造函数,那么你知道你有一个实例任何时候,你可以使用它,而无需调用其他方法)
轻微编辑
我不认为你真的需要bulletOrigin在你的Projectile类中,你可以使用该位置,并从那里移动到bulletDestination。
此外,Vector2类与运营商的重载方法做,所以你可以使用
positionBullet += directionLine*velocity;
,而不是
positionBullet = Vector2.Add(positionBullet, directionLine * velocity);
除了这些,你的代码似乎罚款!告诉我这些更改后它仍然不起作用。另外,使用你的调试器进入它,看看你是否能找到有趣的东西。 :)
哪里的弹丸类的构造函数? – annonymously 2012-01-16 03:38:36