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

Author Topic: multiple setPosition on same object help  (Read 1181 times)

0 Members and 1 Guest are viewing this topic.

bobSavGa

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
multiple setPosition on same object help
« 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;
}
« Last Edit: December 19, 2014, 05:08:25 pm by Laurent »

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: multiple setPosition on same object help
« Reply #1 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();"

bobSavGa

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: multiple setPosition on same object help
« Reply #2 on: December 19, 2014, 05:30:14 pm »
what a dope :(
thanks  vastly

 

anything