SFML community forums

Help => Window => Topic started by: Salmon_Yo on December 06, 2013, 06:06:27 pm

Title: Strange thing with mouse
Post by: Salmon_Yo on December 06, 2013, 06:06:27 pm
Hi guys. I have a little problem. It happens when i`m moving picture in the window and a mouse cursor (in that window) at the same time.. Picture starts to move rather quickly than when coursor don`t move or moving in not my window.. It`s normal?

Maybe it depends ..

#include <SFML/Graphics.hpp>




int main()
{


 
        sf::RenderWindow window(sf::VideoMode(380, 390), "Happines!");
 
       
        sf::RectangleShape s;
        s.setSize(sf::Vector2f(10, 50));
        s.setPosition(10, 50);
        s.setFillColor(sf::Color::Red);


    while (window.isOpen())
    {
       
                 

               
               

               

        sf::Event event;
        while (window.pollEvent(event))
        {

                       

            if (event.type == sf::Event::Closed)
                                window.close();

                       
                       
                       

                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
                               
                                s.move(1, 0);
                               
                               
                        }

               
       
       
                }
               
                window.clear(sf::Color::White);
                       
               
                window.draw(s);
                window.display();
               
                }
       
    return 0;
        }

Video :
http://www.youtube.com/watch?v=3QqN92AKbM4&feature=youtu.be (http://www.youtube.com/watch?v=3QqN92AKbM4&feature=youtu.be)
Title: AW: Strange thing with mouse
Post by: eXpl0it3r on December 06, 2013, 06:12:28 pm
Read the official tutorials again. ;)

sf::Keyboard::isPressed should not be used inside the event loop.
Title: Re: Strange thing with mouse
Post by: Salmon_Yo on December 06, 2013, 06:16:19 pm
Thank you so much=)