Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using XNA, I made a looping background with several textures (whose widths are over 1024px). There are fewer than five of them. All the pictures are different, held in a list and their positions are looped. When it reaches the end of the loop, it flickers.

In my Update method I do this:

dt = (float)gameTime.ElapsedTime.TotalSeconds;
foreach(BackGroundObject bgo in myList)
    bgo.Position += speed * dt;

So that it works based on gameTime. Then, in my drawing function is this code:

foreach(BackGroundObject bgo in myList)
    spriteBatch.Draw(bgo.Picture, bo.Position, Color.White);

Here is the BackGroundObject class. The game holds a list of BackGroundObjects and Update changes their positions. If any object goes off screen, its position is set again; a BackGroundObject is loaded once and the game always uses same BackGroundObjects. MayDraw is a property of the picture's position. I.e. If in the screen or not.

public class BackGroundObject
    public Texture2D Picture;
    public Vector2 Position, DrawPosition;
    public bool MayDraw;

    public BackGroundObject(Vector2 position, Texture2D picture)
        this.Picture = picture;
        this.Position = position;
        this.MayDraw = true;

    public virtual void Draw(SpriteBatch spriteBatch)
        if (MayDraw == true)
            spriteBatch.Draw(Picture, Position, Color.White);

Does the flicker problem occur because of the large image sizes? Could I do this with a shader instead?

My background code works on with a graphic card with 60 FPS, but on a onboard graphic card with 30 FPS.

I have 4 background layers, each layer has 4 pictures, in total about 15pictures are drawen with widths of 1920.

share|improve this question
Why don't you use bgo.Draw(spriteBatch) in your Draw function? It seems to me your MayDraw is never considered based on the code above. – Richard Marskell - Drackir Oct 19 '11 at 16:22
MayDraw is updated in BackGround class, if the picture is not in the game play scene it is not drawed. – icaptan Oct 19 '11 at 16:36
You posted some code above after saying "So that it works based on gameTime. Then, in my drawing function is this code:". That code doesn't take MayDraw into account, it just draws bgo.Picture. You should be calling bgo.Draw(spriteBatch); instead of spriteBatch.Draw(bgo.Picture, bo.Position, Color.White);. – Richard Marskell - Drackir Oct 19 '11 at 16:37
Ops! You detect a nice point ! thanks ! I fix it now ! --> Either the problem does not dissappeared – icaptan Oct 19 '11 at 16:45
You should update your question with the new code. So, how many background images can fit on the screen at once? Three? – Richard Marskell - Drackir Oct 19 '11 at 17:18

It's unclear to me what BackGroundObject is, and how its implemented -- it's possible the problem lies in there, or elsewhere, as the code you've provided doesn't seem terribly suspect. The biggest thing that stands out to me is that you never seem to actually loop (reset) the position of the background images at all. The "Position" value will increase without bound, unless there's a modulus operation that occurs in the setter for that property or something.

You also seem to render all the background images every frame, which is potentially wasteful as probably at most two (given their sizes) will be onscreen at once.

You may want to check out this resource on 2D scrolling background in XNA.

share|improve this answer
i've checked the website, and i use same algorithm with there. I've tested my code on a different machine works with a graphic card (i'm using onboard graphic card) the flickers has ended. has really graphic card a huge effect on simple texture looping ? – icaptan Oct 19 '11 at 16:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.