SFML community forums

Help => Graphics => Topic started by: notpedro on May 21, 2015, 11:15:24 am

Title: Drawing a regularly updating line that changes
Post by: notpedro on May 21, 2015, 11:15:24 am
Im trying to make a program were theres one point at 150, 150 and another point being the cursors location.
And a line is drawn from one point to the second and it keeps updating.

However when I attempted to do this with the following code:
while (true)
        {
                while (window.pollEvent(mapEvent))
                {
                        if (mapEvent.type == sf::Event::MouseMoved)
                        {
                                sf::Vertex line[] =
                                {
                                        sf::Vertex(sf::Vector2f(mapEvent.mouseButton.x, mapEvent.mouseButton.y)),
                                        sf::Vertex(sf::Vector2f(150, 150))
                                };

                                window.clear(sf::Color::Black);
                                window.draw(line, 2, sf::Lines);
                                window.display();
                        }
                }
 

When I do this tho It doesnt work and the line is drawn from the first point to a completely different region.
Why is this happening could anyone shed any light on the cause of this problem?

Gif: http://imgur.com/DNxQErH

EDIt: Oops it didnt show my cursor.
Title: Re: Drawing a regularly updating line that changes
Post by: G. on May 21, 2015, 11:21:58 am
Quote from: http://www.sfml-dev.org/tutorials/2.3/window-events.php#the-mousemoved-event
The member associated with this event is event.mouseMove, it contains the current position of the mouse cursor relative to the window.
if (event.type == sf::Event::MouseMoved)
{
    std::cout << "new mouse x: " << event.mouseMove.x << std::endl;
    std::cout << "new mouse y: " << event.mouseMove.y << std::endl;
}
Not mouseButton.x and y
Title: Re: Drawing a regularly updating line that changes
Post by: notpedro on May 21, 2015, 11:31:05 am
Thanks so much. I had no idea mouse move existed.