Sign in to follow this  
39ster

Scrolling backgrounds

Recommended Posts

I can't figure out how to make the background scroll faster than the the "view". Here's the code i've got so far:
        Background& background = *it;
        Image* image = background.image;

        //Get the "offset"
        float backX = view.x - (floorf(float(view.x) / image->GetWidth()) * image->GetWidth());

        for(int y = 0; y < int(view.h + image->GetHeight()); y += image->GetHeight())
        {
            for(int x = 0; x < int(view.w + image->GetWidth()); x += image->GetWidth())
            {

                graphics.DrawImage(image, view.x - backX + x, view.y + y, 0, 0, image->GetWidth(),
                    image->GetWidth(), view);
            }
        }

....
void DrawImage(Image* image, float x, float y, int left, int top, int width, int height, SDL_Rect& view);
I just need the horizontal scrolling to be faster. [Edited by - 39ster on November 11, 2008 5:10:03 PM]

Share this post


Link to post
Share on other sites
Just in case you're not sure what i mean:

http://en.wikipedia.org/wiki/Parallax_scrolling

I want it to draw like "Layer 1" where it is moving at a different speed than the foreground. Right now it moves at the same speed as the foreground.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this