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

Author Topic: sprite.move is driving me crazy  (Read 1082 times)

0 Members and 1 Guest are viewing this topic.

kjus1245

  • Newbie
  • *
  • Posts: 2
    • View Profile
sprite.move is driving me crazy
« on: July 25, 2013, 04:13:44 am »
I have been trying to solve this for the past hour and I just can't fix it. Whenever I run this the sprite loads on the screen, but when I click the sprite repeats itself every 10 pixels and starts to flash. It seems like when I click, the sprite moves forever.

EDIT::
I added window.clear(); before I draw the sprite, but now it still seems like the sprite is moving multiple times from one mouse click.



int main()
{  

        sf::Texture text1;
        text1.loadFromFile("first.png");

        sf::Sprite sprite1;
        sprite1.setTexture(text1);
        sprite1.setOrigin(0,0);
        sf::RenderWindow window(sf::VideoMode(400, 250), "Preamble", sf::Style::Default);
       



    while (window.isOpen())
    {
               
       



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

                if (event.type == sf::Event::MouseButtonPressed)
                        sprite1.move(10,0);

        window.clear();
        window.draw(sprite1);
        window.display();

}
               
    return 0;
}
« Last Edit: July 25, 2013, 04:17:48 am by kjus1245 »

kjus1245

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: sprite.move is driving me crazy
« Reply #1 on: July 25, 2013, 04:25:13 am »
Just fixed it, instead of using events I changed to a real time system outside of the event loop.

This video here saved me in case anyone had the same problem.

 

anything