焦点移开时,XNA运行缓慢 [英] XNA Is Running Slow when focus is removed

查看:74
本文介绍了焦点移开时,XNA运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,在制作游戏时,我注意到IsRunningSlowly的GameTime值在我的游戏具有焦点时(如应有的那样)返回false,但是当我更改应用程序时,它会变为true.我什至制作了一个空游戏,即使它失去焦点,IsRunningSlowly的GameTime值也返回true.我想知道为什么要这么做吗?仅仅是我的计算机,还是XNA的创建者是以此方式设计的?帧速率看起来不错,但是值是正确的.没什么大不了的,我只是很好奇!

I'm just wondering, while making a game, I noticed that the GameTime value for IsRunningSlowly returns false when my game has focus (like it should), but when I change applications, it changes to true. I even made a empty game, and even when it losses focus, the GameTime value for IsRunningSlowly returns true as well. I'm wondering why does it do this? Is it just my computer, or did the creators of XNA design it this way? The frame rate seems fine, but the value is true. No big deal really, I'm just really curious!

[空游戏]

    public class Game1 : Microsoft.Xna.Framework.Game
{
    #region Constuctors

    public Game1()
    {
        this.GraphicsManager = new Microsoft.Xna.Framework.GraphicsDeviceManager(this);
        this.Content.RootDirectory = "Content";
    }

    #endregion
    #region Overrides

    protected override void LoadContent()
    {
        this.SpriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(this.GraphicsDevice);
        base.LoadContent();
    }
    protected override void Update(Microsoft.Xna.Framework.GameTime GameTime)
    {
        System.Console.WriteLine(GameTime.IsRunningSlowly);
        Microsoft.Xna.Framework.Input.KeyboardState Keyboard = Microsoft.Xna.Framework.Input.Keyboard.GetState();
        if (Keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) this.Exit();
        base.Update(GameTime);
    }
    protected override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
    {
        GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
        base.Draw(gameTime);
    }

    #endregion
    #region Variables

    private Microsoft.Xna.Framework.GraphicsDeviceManager GraphicsManager { get; set; }
    private Microsoft.Xna.Framework.Graphics.SpriteBatch SpriteBatch { get; set; }

    #endregion
}

推荐答案

我将尝试回答该问题,而不是发布这就是事实". XNA线程失去焦点时会进入睡眠状态.它是在XNA的游戏类中配置的.

I'll try and answer the question, and not post a "this is just how it is". The XNA thread sleeps when it loses focus. It is configured in XNA's game class.

InactiveSleepTime = new TimeSpan(0);

默认将其设置为20ms,将其设置为0将使XNA在失去焦点的情况下全速运行.

It's set to 20ms by default, and setting it to 0 will make XNA run full speed while it has lost focus.

IsRunningSlowly设置为true,因为帧率降至60以下(这是设置IsFixedTimeStep时的默认值)

IsRunningSlowly gets set to true since the framerate drops below 60 (which is the default when IsFixedTimeStep is set)

这篇关于焦点移开时,XNA运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆