SFML community forums

Help => Graphics => Topic started by: bobSavGa on December 19, 2014, 04:53:53 pm

Title: multiple setPosition on same object help
Post by: bobSavGa on December 19, 2014, 04:53:53 pm
the code works perfectly, but flashes, with the clear commented out but shows a blank screen with clear.
help???

#include <SFML/Graphics.hpp>

int main(int argc, char *argv[]) {
        sf::RenderWindow window(sf::VideoMode(600, 600), "SFML works!");
        sf::CircleShape shape(10.f);
        int x, stop, increment;
        //stop must be bigger than start
        //change 10 to the desired start value
        x = 10;
        //change 600 to the stopping point
        stop = 600;
        //change 20 to the table increment
        increment = 20;
        shape.setFillColor(sf::Color::Green);

        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                window.clear();
                for (; x <= stop; x = x + increment) {
                        shape.setPosition(x, x);
                        window.draw(shape);
                }
                window.display();
        }
        return 0;
}
Title: Re: multiple setPosition on same object help
Post by: Raincode on December 19, 2014, 05:25:15 pm
you forgot to reset x back to 10 (or whatever it shall be). Thus, soon x lies outside of the bounds of your window, and you cannot see the circle(s) anymore.

So try adding "x = 10;" after "window.display();"
Title: Re: multiple setPosition on same object help
Post by: bobSavGa on December 19, 2014, 05:30:14 pm
what a dope :(
thanks  vastly