I know that its just the background that scrolls and the player pretty much stays centered. What I am wondering what technique is more correct when I am implementing a large side scrolling map (I am not using tiles like some other questions I have found).

using a very large map 16000 pixels map, and scrolling that. and create an image list, with maybe 4 4000 pixel maps?

also, lets say I want a box at a certain point in my map. Right now I am just counting the pixels that I am scrolling and once I get to pixel 2000 I insert the box, and scroll it with the background. Does that seem correct? or is there a better way to do all of this?


2 Answers 2


If you are using SpriteBatch:

  • Draw everything (SpriteBatch.Draw) in its "world space"
  • Pass a translation matrix to SpriteBatch.Begin to translate your world space to the correct position (think of this like a camera).
  • The maximum texture size in XNA is 2048x2048 on the Reach profile, 4096x4096 for HiDef (details). If your background texture is bigger, you will have to split it up and draw it in parts.
  • You may want to consider adding some culling if you hit performance issues.

You should do all your movement calculations and so on in that "world space". So that box would have a position of something like new Vector2(2000, 0).

Your player would also have a Vector2 position; and probably also something like a Vector2 velocity. You would then Draw the player sprite at that position. And also use that position to create your camera matrix.

For really huge worlds, or for physics engines that require precision, you may need to mess about rebasing your world space to maintain precision (details). I imagine that this probably doesn't apply to your situation.


Use an image list. (Is more memory friendly - although pay attention to the garbage collector)

Counting pixels can be good or bad. Depends on the complexity of your game. Pro: - it's pretty WYSIWYG. - it is simple to understand what's happening

Con: - Your smallest step-size is one pixel - maybe you want to be able to be more precise with your controls

My suggestion: If your game is reasonably simple use pixels. Otherwise calculate everything in a continuous space.

  • \$\begingroup\$ calculate everything in a continuous space seems like a good idea... if only I knew what that was. \$\endgroup\$
    – bitbitbot
    Commented Apr 1, 2011 at 20:32
  • 1
    \$\begingroup\$ The continuous space is where you do vector geometry ;-) If you aren't very comfortable with linear algebra, stay with the pixels (or go to khanacademy.org and learn it) \$\endgroup\$
    – Fabian
    Commented Apr 1, 2011 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .