Jump to content
  • Advertisement
Sign in to follow this  
Evil Booger

Scrolling background in C++

This topic is 4861 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

How do I make the (2D)background scroll like in adventure games. ps, this is my first post so please excuse me if I do anything wrong.

Share this post


Link to post
Share on other sites
Advertisement
Welcome to gamedev!
We need a bit more information than that. Which graphics library are you using, are the backgrounds bitmapped or tilebased or something else entirely, do you need special effects like parallax scrolling, how large can they become?

Share this post


Link to post
Share on other sites
If I understand you correct then you have a big pic but it doesn't completely fit on the screen (for example a room) and you want to scroll it a little...
If the image isn't too big then I would load it completely and then use the source rectangle to cut your screen out of it. you can just in/de-crease the x-value of it to scroll... I drew a small pic to show what I mean... My English isn't good enough..


if you are using SDL then

SDL_Rect src, dest;

src.x = 0; <----------------you should change this to scroll horizontal
src.y = 0;
src.w = image->w;
src.h = image->h;
image
dest.x = 100;
dest.y = 100;
dest.w = image->w;
dest.h = image->h;

SDL_BlitSurface(image, &src, screen, &dest);

Share this post


Link to post
Share on other sites
Ok, will you draw only one biiig background or do you have small parts of background pieces?
The method with the source rect is only suitable if you are using a big pic but using a big pic isn't very suitable for a game in which the level is very big.
You could tell us:
Are you using DirectX, OpenGL or something like SDL, Allegro
What do you want to know exactly? Do you want the technique explained or do you want sample code?
Are you using tiles or a huge pic?


edit: Ok, didn't see your last post.
Just cut a small part out of the big. You can specify the source rect and just increase/decrease the x and y values of it. Then just blit it on your screen.

Share this post


Link to post
Share on other sites
google :)

Simple DirectMedia Layer

something which makes 2D programming much easier...
I think it's perfect for beginners because you can concentrate on more important things and still learn a lot about game programming. later you'll need more and probably 3D (ok, you can use OpenGL with it but that's another topic). There are tons of tutorials for it.

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!