Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scrolling Background  (Read 1193 times)

0 Members and 1 Guest are viewing this topic.

noaboa

  • Newbie
  • *
  • Posts: 14
    • View Profile
Scrolling Background
« 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));
}
}


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Scrolling Background
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*