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

Author Topic: Drawing a regularly updating line that changes  (Read 1619 times)

0 Members and 1 Guest are viewing this topic.

notpedro

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Drawing a regularly updating line that changes
« 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.
« Last Edit: May 21, 2015, 11:20:39 am by notpedro »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Drawing a regularly updating line that changes
« Reply #1 on: May 21, 2015, 11:21:58 am »
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

notpedro

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Drawing a regularly updating line that changes
« Reply #2 on: May 21, 2015, 11:31:05 am »
Thanks so much. I had no idea mouse move existed.