我找到了自己问题的解决方案。最好的方法是创建一个 XNA 2D 应用程序。我在我的显卡设置中强制使用 vsync。然后我在 XNA 应用程序中打开了这个属性。在游戏构造函数中,我使用了这个: this.IsFixedTimeStep = true;
public Game1()
{
this.IsFixedTimeStep = true;
this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 1000 / 60);//60 times per second
graphics = new GraphicsDeviceManager(this)
{
PreferredBackBufferWidth = 800,
PreferredBackBufferHeight = 600,
SynchronizeWithVerticalRetrace = true,
};
graphics.ApplyChanges();
Content.RootDirectory = "Content";
}
然后声明一个全局变量: bool _IsDirty = true; 并声明以下函数:
protected override bool BeginDraw()
{
if (_IsDirty)
{
_IsDirty = false;
base.BeginDraw();
return true;
}
else
return false;
}
protected override void EndDraw()
{
if (!_IsDirty)
{
base.EndDraw();
_IsDirty = true;
}
}
protected override void Draw(GameTime gameTime)
{
//graphics.GraphicsDevice.Clear(Color.Black);
// Draw the sprite.
spriteBatch.Begin();
spriteBatch.Draw(textureImg, new Rectangle(0, 0, 800, 600), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}