2011-07-15 51 views
0

我有Windows XP SP3。XNA 3.1 Laggy運動

我創建的默認XNA項目3.1版本,並添加這些簡單的線條來預生成代碼:

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); 
    } 
} 

這樣簡單!但是這個運動非常緩慢,它閃爍,我甚至無法看到它。 如果我將它與某些Flash遊戲進行比較,則無法比擬。爲什麼是這樣?我究竟做錯了什麼?

+1

需要注意的是XNA 4.0已經出來一段時間,就是你現在應該使用什麼。 –

+0

我測試了你的代碼(儘管在XNA 4的Vista中),並沒有閃爍,口吃或任何種類的滯後(我也不希望XP和XNA 3.1都有)。你是否能夠正常玩GPU加速遊戲,無滯後?你有沒有發佈的代碼? –

+0

你確定在XP和vista之間運行XNA和之後沒有區別嗎?我從來沒有在這臺電腦上玩過遊戲..是的,它是完整的代碼發佈。難道我錯過了一些驅動程序/庫來訪問GPU嗎?無論如何,這樣一個簡單的例子必須通過cpu順利模擬,還是我錯了? –

回答

1

因爲您正在使用矩形的X和Y分量,所以您的計算將四捨五入到最接近的整數。在這種情況下,你需要精細的運動。

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(); 
+0

當人們提出這個建議時,它讓我感到困擾,因爲默認情況下,XNA通過跳過繪製方法來補償滯後。除非你以固定的時間步長運行你的遊戲,否則你應該真的不需要這麼做。 –

+0

我改變了我的答案,以便它更加正確,這是你期望的@Ruirize? –

+0

那麼IsFixedTimeStep是什麼?它會影響運動的流暢程度嗎? –