【问题标题】:XNA temporary pauseXNA 临时暂停
【发布时间】:2014-06-09 07:29:24
【问题描述】:

我需要暂停一下。如果我与敌人发生碰撞,我想暂停游戏 1.5 秒。看看我的代码:

bool tPause;
float timer;

public ovveride Update(GameTime gameTime)
{
    if(!tPause)
        {
            //...
            if(enemy.rectangle.Intersects(player.rectangle))
            {
                timer+=(float)gameTime.ElapsedGameTime.TotalMilliseconds;
                tPause=true;
                if(timer>1500)
                {
                    tPause=false;
                    timer=0;
                }
            }
            //...
        }
}

它不起作用!我可以修改什么?

【问题讨论】:

    标签: c# xna 2d-games


    【解决方案1】:

    即使游戏暂停,也要不断更新计时器。此外,我会倒数:

    if(timer <= 0) //!tPause
    {
        //...
        if(enemy.rectangle.Intersects(player.rectangle))
        {
            timer = 1500; //initialize a 1.5 second pause
        }
    }
    else
        timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 2013-11-16
      • 2021-11-19
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      • 2013-02-05
      相关资源
      最近更新 更多