我有一个使用 XNA/C# 为 Windows 手机制作的游戏,现在我决定去添加一个 Bomb 来帮助玩家。
现在我已经设置了一个计时器和一个布尔值,因此每个级别只能使用 1 个炸弹。
但是,游戏一开始,炸弹就已经在那里了!我不认为计时器在工作。
bool canDrawBomb = false;
public static Texture2D bomb;
GameTimer bombTimer = new GameTimer();
protected override void Initialize()
{
// Bomb timer.
bombTimer.UpdateInterval.Add(new TimeSpan(50000));
bombTimer.Update += bombTimer_Update;
bombTimer.Start();
base.Initialize();
}
void bombTimer_Update(object sender, GameTimerEventArgs e)
{
canDrawBomb = true;
bombTimer.Stop();
}
protected override void LoadContent()
{
bomb = Content.Load<Texture2D>("Bomb");
}
protected override void Draw(GameTime gameTime)
{
if (canDrawBomb)
{
// Draw the bomb.
// TESTED: OK. The bomb can draw but not at right time.
spriteBatch.Draw(bomb, new Vector2(), Color.White);
}
}
现在的问题是,即使我将bombTimer 设置为ah 50 秒,它仍然在游戏开始时绘制!
我怎样才能解决这个问题?我已经在这里待了好几个小时,这让我发疯了。我不知道我做错了什么!