I’m trying to define the timespan between shots during constant fire, but got weird behavior with the following attempt:
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);
}
The above is called by this:
if (newMouseState.LeftButton == ButtonState.Pressed)
{
if (oldMouseState.LeftButton == ButtonState.Released)
{
player.Shoot(time);
gui.ProcessClick(newMouseState);
}
else
player.ShootContinuous(time);
}
Well, the behaviour is like this: While holding the button, it shoots a volley with a random bullet count between 4-10 and then does nothing until I realese the button, wait a moment and shoot again.
Anyone has an idea what wrong with this?
You should use
TotalMilliseconds, notMilliseconds, if I understand the code correctly.