Jump to content
  • Advertisement
Sign in to follow this  
39ster

Scrolling backgrounds

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

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
Advertisement
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
Thanks, but that does this weird "skipping" thing when i use 0.5 as the speed. It will scroll half way then suddenly skip back.

Share this post


Link to post
Share on other sites
apologies.. guess I should of read your code a bit harder xD
float backX = (view.x * 0.5f) - (floorf(float(view.x * 0.5f) / image->GetWidth()) * image->GetWidth());
that work okay?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!