我正在尝试定义持续射击期间射击之间的时间跨度,但是通过以下尝试得到了奇怪的行为:
public void Shoot(GameTime time)
{
bullets.Add(new Bullet("bullet", position, angle, content, this, bullets) );
shotTimer = time.TotalGameTime.Milliseconds;
}
public void ShootContinuous(GameTime time)
{
if (time.TotalGameTime.Milliseconds - shotTimer > 50)
this.Shoot(time);
}
上面是这样调用的:
if (newMouseState.LeftButton == ButtonState.Pressed)
{
if (oldMouseState.LeftButton == ButtonState.Released)
{
player.Shoot(time);
gui.ProcessClick(newMouseState);
}
else
player.ShootContinuous(time);
}
好吧,行为是这样的:按住按钮时,它会以 4-10 之间的随机子弹数进行齐射,然后什么都不做,直到我重新按下按钮,稍等片刻,然后再次射击。
有人知道这有什么问题吗?