SFML community forums

Help => General => Topic started by: noaboa on January 20, 2016, 05:38:16 pm

Title: Scrolling Background
Post by: noaboa on January 20, 2016, 05:38:16 pm
Hi, I am trying to make a platform game, and have made an animation sprite, and a scrolling background by myself. I tried to make a scrolling background when I am walking backwards but I can't make it. Here is the relevant code. How can I make it so it will scroll if i walk backwards?

Code: [Select]
void main_game::ScrollingBackground(){
if (background1->getPosition().x < -background1->getGlobalBounds().width){
std::cout << "Out on the right side\n";
this->background1->setPosition(sf::Vector2f(this->background1->getGlobalBounds().width - 1, -50));
}
else if (background2->getPosition().x < -background2->getGlobalBounds().width){
std::cout << "Out on the right side\n";
this->background2->setPosition(sf::Vector2f(this->background2->getGlobalBounds().width - 1, -50));
}
}

Title: Re: Scrolling Background
Post by: Hapax on January 20, 2016, 09:03:06 pm
What exactly is the problem you are having?
To scroll in the opposite direction, do what you do the other way around.

You may want to consider using a view to "scroll" and then just draw the part of the background that are within the view.