Devon Fritz

I am new to XNA, but I followed some simple tutorials to load a small image, get it on screen, and move it around. I've noticed that for the most part, the updating of graphics is smooth, but every few seconds the update to the display "misses a beat" or something and the on screen sprite jumps instead of moving smoothly. I have changed the display to show one hundred images and do the same test, and I get the same result (it doesn't even get worse). I've confirmed this happens on a friend's top of the line computer as well. I can't imagine anything I am doing is that intensive...I have made games in DirectX before and have not had this issue. I have a breakpoint in gameTime.IsGameRunningSlowly (forgive me, I forget the exact property name...I can't access the code right now) that never gets hit, so that isn't the issue.

To sum up, I took basic skeleton code, added one Texture and put it on screen. I made it so that simple input moves it around, and I am experiencing some "chop". Is anyone else having this issue Thank you!


Re: XNA Game Studio Express Slight Lag in XNA?

dczraptor

It's probably related to the garbage collector, because it runs every couple of seconds. Are you sure you aren't creating a texture/model in every update/draw call Also, if you print out massive amounts of text via the console, then it might also contribute to a slowdown, but I don't think that's the case for you.






Re: XNA Game Studio Express Slight Lag in XNA?

Jim Perry

Any slow down like this is the result of bad code and since you didn't post any we can't really help you.




Re: XNA Game Studio Express Slight Lag in XNA?

waruwaru

When I run one of the text components on CodePlex, I can see a slight pause once every second. Some people think it's because the vertical sync rate, so it was missing a frame every second. People recommended playing with your graphics card's refresh rate setting. I havn't really bothered to tweak mine yet so I dunno if that works.




Re: XNA Game Studio Express Slight Lag in XNA?

Kyle_W

I have seen the same issue with a simple 3D model rotation animation I did, but it only really happens when I am running the app from inside of Visual Studio Express in debug mode. If I build the project and run it directly from the release folder I don't see the hiccups. It seems like it may also be related to other processes I had running. In other words when I shut down most of the extra junk I run on a daily basis it seemed to get better. Some background process might be spiking the CPU periodically. Lastly I would suggest that these sort of hiccups probably even occur occasionally in professional games, but usually there is so much going on on the screen that they are hardly noticed or attributed to lag, etc.



Re: XNA Game Studio Express Slight Lag in XNA?

Devon Fritz

I didn't think the code would be all that helpful, but here it is:

/////////////CODE START
public class TestGame : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
ContentManager content;


private Texture2D SpriteTexture;
private SpriteBatch ForegroundBatch;
int xloc = 0;
int yloc = 0;

public TestGame()
{
graphics = new GraphicsDeviceManager(this);

content = new ContentManager(Services);

graphics.PreferredBackBufferWidth = 1024;
graphics.PreferredBackBufferHeight = 768;
graphics.IsFullScreen = false;

this.IsFixedTimeStep = true;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
ForegroundBatch = new SpriteBatch(graphics.GraphicsDevice);
SpriteTexture = content.Load<Texture2D>("test");
}

}
protected override void Update(GameTime gameTime)
{
// Allows the default game to exit on Xbox 360 and Windows
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

if (GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Right))
{
xloc += 5;
}
base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

ForegroundBatch.Begin();
ForegroundBatch.Draw(SpriteTexture, new Rectangle(0+ xloc, 0+yloc, 64, 64), new Rectangle(0, 0, 64, 64), Color.White);
ForegroundBatch.End();

base.Draw(gameTime);
}
///////////////////////////CODE END

Something else I have noticed...I notice considerably more chop when displaying in full screen mode (even though the resolution and everything else are the same). The chop doesn't discriminate: it manifests down to resolutions of 640x480 as well.




Re: XNA Game Studio Express Slight Lag in XNA?

Jim Perry

Assuming you're drawing the whole sprite there's no reason for specify the source rect. There's also no reason to add 0 to the x and y (although the compiler most likely strips it out anyway). I whipped up a quick sample and didn't notice any choppiness.




Re: XNA Game Studio Express Slight Lag in XNA?

Devon Fritz

I have new incite (and have more reason to believe the problem isn't in my code). I've downloaded a tutorial called "The Wizard" at: http://www.xnadevelopment.com/tutorials.shtml

I removed the animations on the wizards movement and made him twice the size, but I still get the jumpiness every few seconds. I will say that I did have a much harder time detecting it when the sprite was animated, but it definitely exists. I've now tested this on 3 machines, as well. An input that anyone could give would be great. Thank you.




Re: XNA Game Studio Express Slight Lag in XNA?

Devon Fritz

Jim Perry,

Thank you for your response. It actually is just a section of the image, so that is why i passed in the source rectangle. You are right about me not having to add 0, I was just writing donkey code to get something working. You compiled this code with a sample image and didn't see any choppiness Did you look for multiple seconds This might be a dumb question, but what type of display do you have All three that I have tested on are LCDs...maybe that has something to do with it




Re: XNA Game Studio Express Slight Lag in XNA?

dczraptor

How good are your machines If they're running on slow cpus or graphics cards, that might be it. However, I've ran many games on my nvidia 5600 (ancient in terms of graphics cards) with no chop, so I'm not sure if it's the culprit.

And make sure you aren't running any extraneous programs. Open up your task manager and see how much % your processes are using.






Re: XNA Game Studio Express Slight Lag in XNA?

r2d2-proton

This is classic.

Yes, I witnessed the stuttering at different Hz on my monitor.

If you set :

graphics.SynchronizeWithVerticalRetrace = false;

this.IsFixedTimeStep = false;

you¡¯ll get the fastest response. However, it¡¯s a little wild and the draws aren¡¯t crisp. Setting either one to true changes the mood :)

That¡¯s why GameTime is passed around ¨C so you can compensate for the missed beats.

Stepping at 5 while crossing 1024 takes 205 steps. If you¡¯re tied to VSync @ 60 Hz that¡¯s roughly 3.4 seconds ¨C a little slow. And @ 85 Hz it¡¯s 2.5 seconds.

That just seems a little too slow for game movement.