XNA,gameTime和恒定的火力

时间:2012-05-25 09:41:43

标签: c# time xna controls

我试图在持续射击期间定义镜头之间的时间跨度,但是通过以下尝试获得了奇怪的行为:

    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之间随机发射一次子弹,但在我按下按钮之前什么都不做,等一会再拍。

任何人都知道这有什么问题吗?

1 个答案:

答案 0 :(得分:1)

如果我理解正确的代码,您应该使用TotalMilliseconds,而不是Milliseconds