我找到了解決我自己的問題。最好的方法是創建一個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";
}
然後聲明一個全局變量: 布爾_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);
}