對於開始,你能移動
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