Update: I uploaded a video showing stuttering here: http://intninety.co.uk/xnastutter.mp4 you may have to look carefully at the video if you are not watching it in 1920x1080 format, but you will see that every move For 2 seconds or so, a rather sharp stutter is observed, I would recommend viewing it in Windows Media Player, and not in your web browser, to ensure the video itself is intermittent and thus preventing you from seeing the actual stutter
I recently picked up a project that I started some time ago, however, I'm still trying to solve the problem on which I left it!
I currently have a very simple application that has only one sprite on the screen and is moved using the direction keys. The problem is, every two seconds or so, the game stutters, and the sprite seems to jump back and then back and forth very quickly.
The sprite itself is a 55x33 bitmap, so it is not something big, and the code used is as follows. I hope this is enough to make the ball roll on some ideas as to what might be the problem if a video is needed, to see exactly what the stutter looks like, I can put it together and load it somewhere if necessary.
As you will see in the code, it compensates for the lost time between frames, making the movement larger if this happens, however this fall occurs very consistently, wise, which makes me think that I am doing something wrong somewhere.
I tried on several different machines, but the problem persists for all of them, if anyone has any ideas or you can see where I, I messed it up, would be greatly appreciated if you could point it out.
Thanks:)
Game Designer Configuring the Graphics Device Manager
graphics = new GraphicsDeviceManager(this); graphics.IsFullScreen = true; graphics.SynchronizeWithVerticalRetrace = false; graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; Content.RootDirectory = "Content"; this.IsFixedTimeStep = false;
Code from the game update method
KeyboardState keyboard = Keyboard.GetState(); GamePadState gamePad = GamePad.GetState(PlayerIndex.One); if (keyboard.IsKeyDown(Keys.Escape)) { this.Exit(); } if ((keyboard.IsKeyDown(Keys.Left)) || (gamePad.DPad.Left == ButtonState.Pressed)) { this.player.MoveLeft((float)gameTime.ElapsedGameTime.TotalMilliseconds); } else if ((keyboard.IsKeyDown(Keys.Right)) || (gamePad.DPad.Right == ButtonState.Pressed)) { this.player.MoveRight((float)gameTime.ElapsedGameTime.TotalMilliseconds); } if ((keyboard.IsKeyDown(Keys.Up)) || (gamePad.DPad.Up == ButtonState.Pressed)) { this.player.MoveUp((float)gameTime.ElapsedGameTime.TotalMilliseconds); } else if ((keyboard.IsKeyDown(Keys.Down)) || (gamePad.DPad.Down == ButtonState.Pressed)) { this.player.MoveDown((float)gameTime.ElapsedGameTime.TotalMilliseconds); } base.Update(gameTime);
The Move methods described in the above update method
public void MoveLeft(float moveBy) { this.position.X -= (moveBy * this.velocity.X); } public void MoveRight(float moveBy) { this.position.X += (moveBy * this.velocity.X); } public void MoveUp(float moveBy) { this.position.Y -= (moveBy * this.velocity.Y); } public void MoveDown(float moveBy) { this.position.Y += (moveBy * this.velocity.Y); }
Game drawing method
GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(this.player.Texture, this.player.Position, null, Color.White, this.player.Rotation, this.player.Origin, 1.0f, SpriteEffects.None, 0.0f); spriteBatch.End(); base.Draw(gameTime);
Edit: forgot to mention, the speed object used in the Move methods is Vector2