Jump to content
  • Advertisement
Sign in to follow this  
martini1

Scrolling background???

This topic is 3468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im using Visual C++ 2005 to program a 2D spaceship navigating across a scrolling background. The background is a simple picture, which I have copied and pasted a few times to extend it in paint. It worked fine when it was 7mb. But, now that it is 18mb the mountains are now just flat lines stretching across the screen. Is there a limit to the size of the picture that one can used?

Share this post


Link to post
Share on other sites
Advertisement
No not really, but it depends on how you use it.
You must give much more details, such as how you load the image, how you store the image, how you draw the image, etc. To answer your question we must now if it's in video memory or RAM, and what API is used to draw it, and how you code it, what operating system you have, what programming language you use.

Share this post


Link to post
Share on other sites
Quote:
The background is a simple picture, which I have copied and pasted a few times to extend it in paint.


If I am understanding you correctly, you are manually copying and pasting an image A to create an image x*A, where is x is the number of copy-n-pastes? If so, this is an inefficient method; you would benefit yrself if you "copy-n-pasted" in the code.

I am not sure what API you are using, but you should do the following:

1. Load up one copy of the minimal background image (the original where no copying-n-pasting was performed).

2. For sake making the explanation easier, just consider scrolling in one axis ==> the y-axis.

3. For the first frame you will blit the whole background image to the screen.

4. But as you move up in the spaceship, the background should move down to give the illusion of scrolling. So the background must be blit with an offset, corresponding to how far the ship has moved with respect to the background.

5. This will cause a portion of the background image to fall off the screen. But do not blit this wasteful portion. Instead you want to wrap it up to the top of the screen.

6. Simply blit the portion of the background that would've fallen off the screen to the top of the screen to effect the illusion of a continuous scrolling landscape.


If this is too hard to understand I could post some pseudo code. But in this method you are only storing in memory the smallest, original image; you are just manipulating its presentation and blitting the pieces where they need to be.

Share this post


Link to post
Share on other sites
Well this is not so much a fix but something you may want to consider.

Instead of having one huge image to scroll through as the level progress it may be a better idea to break it down into smaller bits and here is a short list of reasons.

Reasons:

1) Its not much harder to code a scrolling bit to use more images then one.

2) you get to uses the images more then one time eg for more then one level or multiple times in a single level.

3) You can use one image and mirror it so that it look different but is actually the same one seen in a previous section of the level or in a previous level.

4) Can be more friendly on memorie if you end up reusing older images to extend the level.

By breaking it down it actually gives you more freedom to build more dynamic and longer levels in my oppion.

And as for the limit to image size the answer is no and yes it is based on your Gfx card and memorie in the machine and other variables but as a general rule no there is no limit but the hardware's.

Regards Jouei.





Share this post


Link to post
Share on other sites
Hmmm...I'm using the following to blit the image, which works, but I like the sound of the - re-using the same image approach...

void Camera::DrawBackground(void)
{
RECT destRect, sourceRect;

//The background source pictures coodinates
sourceRct.top = (int)v2dViewPoint.YValue;
sourceRct.bottom = (int)v2dViewPoint.YValue + CAMERA_HEIGHT-2;
sourceRct.left = (int)v2dViewPoint.XValue;
sourceRct.right = (int)v2dViewPoint.XValue + CAMERA_WIDTH;

//Set background to screen coordinates
destRct.top = 0;
destRct.bottom = CAMERA_HEIGHT;
destRct.left = 0;
destRct.right = CAMERA_WIDTH;

pDrawEngine->Blit(destRect, sourceRect, pBackgroundPic);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!