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]
Scrolling backgrounds
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:
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.
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.
backX *= 2.0f;
(after initialisation. for a 2x rate of scroll)Unless I'm missing something :]
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.
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement