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.
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