Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
calculate everything in a continuous space seems like a good idea... if only I knew what that was. –  bitbitbot Apr 1 '11 at 20:32
1  
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) –  Fabian Apr 1 '11 at 20:48

Your Answer

 
discard

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.