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

Author Topic: [SOLVED] Making Scrolling Backgrounds  (Read 6796 times)

0 Members and 1 Guest are viewing this topic.

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
[SOLVED] Making Scrolling Backgrounds
« 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  :-\
« Last Edit: November 23, 2016, 05:56:05 am by Carlos Augusto Br Cpp »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SOLVED] Making Scrolling Backgrounds
« Reply #1 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.
Laurent Gomila - SFML developer

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Re: [SOLVED] Making Scrolling Backgrounds
« Reply #2 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...

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: [SOLVED] Making Scrolling Backgrounds
« Reply #3 on: November 23, 2016, 08:56:55 pm »
Although you have stated that this is solved, you may find this post useful.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Re: [SOLVED] Making Scrolling Backgrounds
« Reply #4 on: November 23, 2016, 11:14:22 pm »
Thanks bro...  :)