SFML community forums

Help => Graphics => Topic started by: Carlos Augusto Br Cpp on November 23, 2016, 03:24:10 am

Title: [SOLVED] Making Scrolling Backgrounds
Post by: Carlos Augusto Br Cpp on November 23, 2016, 03:24:10 am
Hey guys... hope that you are fine... I am having one problem... I have got it to make scrolling objects... I have made an paddle and when it reach the end of the window it generate in the other side of screen... it works fine... but the problem is that I want to make scrolling backgrounds... I more or less know that I have to repeat the texture but I dont know how... I will post here the code of how I made the scrolling paddle:

#include <SFML/Graphics.hpp>

int main(int argc, char* argv[])
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Scrolling Test");
    window.setVerticalSyncEnabled(true);


    sf::RectangleShape shape(sf::Vector2f(200,30));
    shape.setPosition(200, 400);
    shape.setFillColor(sf::Color::Blue);

    sf::Clock clock;

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }

        if ((shape.getPosition().x + shape.getSize().x) < 0)
        {
            shape.setPosition((window.getSize().x), (shape.getPosition().y));
        }

        float deltaTime = clock.restart().asSeconds();

        shape.move(-deltaTime * 500, 0);

        window.clear();
        window.draw(shape);
        window.display();
    }
}
 

but the real questions is: How I can apply this to an scrolling background? and how I correctly repeat an texture?

p.s: Sorry about bad English  :-\
Title: Re: [SOLVED] Making Scrolling Backgrounds
Post by: Laurent on November 23, 2016, 08:39:41 am
If it is solved then please update your post (or post a reply), so that people don't answer uselessly.
Title: Re: [SOLVED] Making Scrolling Backgrounds
Post by: Carlos Augusto Br Cpp on November 23, 2016, 12:44:08 pm
I have tried to search around while I dont had awnsers... and a member have helped me... so I got it to repeat the texture and make it scroll with a mix of texture rect and a condition to update if the width come to to the end...
Title: Re: [SOLVED] Making Scrolling Backgrounds
Post by: Hapax on November 23, 2016, 08:56:55 pm
Although you have stated that this is solved, you may find this post (http://en.sfml-dev.org/forums/index.php?topic=14382.msg101171#msg101171) useful.
Title: Re: [SOLVED] Making Scrolling Backgrounds
Post by: Carlos Augusto Br Cpp on November 23, 2016, 11:14:22 pm
Thanks bro...  :)