XNA 3.1滞后运动

XNA 3.1滞后运动,xna,game-physics,Xna,Game Physics,我有Windows XP SP3。 我在3.1版中创建了默认XNA项目,并在预生成的代码中添加了以下简单行: public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Rectangle rectangle = new Rectangle(80, 80, 100, 100); Texture2D te

我有Windows XP SP3。

我在3.1版中创建了默认XNA项目,并在预生成的代码中添加了以下简单行:

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;

    SpriteBatch spriteBatch;
    Rectangle rectangle = new Rectangle(80, 80, 100, 100);  
    Texture2D textureTrain;     

    public Game1()
    {            
        graphics = new GraphicsDeviceManager(this);     
        Content.RootDirectory = "Content";

        //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 10);
    }
...

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);      

        // TODO: use this.Content to load your game content here
        textureTrain = Content.Load<Texture2D>("MyBitmap1");
    }
...

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here
        rectangle.X = rectangle.X + 1;
        rectangle.Y = rectangle.Y + 1;

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        // TODO: Add your drawing code here
        spriteBatch.Begin();        
        spriteBatch.Draw(textureTrain, rectangle, Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
矩形矩形=新矩形(80,80,100,100);
纹理2d纹理;
公共游戏1()
{            
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
//targetReleasedTime=新的时间跨度(0,0,0,0,10);
}
...
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
textureTrain=Content.Load(“MyBitmap1”);
}
...
/// 
///允许游戏运行逻辑,例如更新世界,
///检查碰撞、收集输入和播放音频。
/// 
///提供计时值的快照。
受保护覆盖无效更新(游戏时间游戏时间)
{
//允许游戏退出
if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)
这是Exit();
//TODO:在此处添加更新逻辑
矩形.X=矩形.X+1;
矩形.Y=矩形.Y+1;
更新(游戏时间);
}
/// 
///这就是所谓的比赛应该平局的时候。
/// 
///提供计时值的快照。
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
//TODO:在此处添加图形代码
spriteBatch.Begin();
spriteBatch.Draw(纹理贴图、矩形、颜色、白色);
spriteBatch.End();
基础。抽签(游戏时间);
}
}
就这么简单!但是这个动作非常滞后,它忽隐忽现,我甚至不能看它。
如果我把它和一些flash游戏相比,它是无与伦比的。为什么会这样?我做错了什么?

因为您使用的是矩形的X和Y分量,所以您的计算将四舍五入到最接近的整数。在这种情况下,您需要精细、精确的移动

i、 e


当人们建议这样做时,我很恼火,因为默认情况下,XNA通过跳过draw方法来补偿延迟。除非你在固定的时间段内运行游戏,否则你真的不需要这样做。我更改了我的答案以便更准确,这是你所期望的@Ruirize吗?IsFixedTimeStep是什么?这会影响动作的流畅性吗?谢谢你改变它。我最近看到很多人把老把戏误认为是XNA自动修复的东西。IsFixedTimeStep基本上控制帧跳过。如果你的游戏落后了,它会掉帧。将此设置为true将禁用此行为。但它不应该引起闪烁。你有什么建议吗?2d游戏的固定或非固定时间步进?请注意,XNA 4.0已经推出一段时间了,您现在应该使用它。我测试了您的代码(尽管是在XNA 4的Vista上),没有任何闪烁、结巴或延迟(我也不希望XP和XNA 3.1上会出现)。你能正常玩GPU加速的游戏吗?有没有你没有发布的代码?你确定在XP和vista上运行XNA和更高版本没有区别吗?我从未在这台电脑上玩过游戏。。是的,这是发布的完整代码。是不是我错过了一些访问gpu的驱动程序/库?无论如何,这样一个简单的例子必须由cpu平滑地模拟,否则我错了吗?
Vector2 position = new Vector2(0.1f, 0.1f);
//Some Arbitrary movement
float speed = 0.008f;
position.X += (float)((speed * position.X);
position.Y += (float)((speed * position.Y);

spriteBatch.Begin();
spriteBatch.Draw(textureTrain, position, rectangle, Color.White);
spriteBatch.End();