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

Author Topic: Strange Event.mouseButton.x / y behaviour?  (Read 1975 times)

0 Members and 1 Guest are viewing this topic.

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
Strange Event.mouseButton.x / y behaviour?
« on: May 14, 2012, 05:46:10 am »
Hi there...

check this code snipit

sf::Event event;

// Mouse Position tmp Variables
        sf::Vector2i position = sf::Mouse::getPosition(window);

<SNIP A LARGE CHUNK OF CODE>

                        case sf::Event::MouseMoved:

                                position=sf::Mouse::getPosition(window);
                                std::cout<<"Position X = "<<position.x<<" Y = "<<position.y<<std::endl;
                                std::cout<<"mouseButton.x = "<<event.mouseButton.x<<" Y = "<<event.mouseButton.y<<std::endl;
                                std::cout<<"Mouse moved - X: "<<event.mouseMove.x<<" Y: "<<event.mouseMove.y<<std::endl<<std::endl;

                                break;

it is my understanding that event.mouseButton.x returns the current mouse position before the mouse is moved, unlike event.mouseMove.x witch returns the x position of where the mouse was moved to? What is happening though is mouseButton.X is giving me the window cords of the mouse's Y position and the .y is returning junk.

here is a example of what si wrong - http://screencast.com/t/U2JgoqR1e

What I am trying to do is simply make left or right mouse moment to move teh block left or right, but not have it relative to mouse position, so it is just testing that the mouse moved left or right, not to were it is pointing at all. The plan was to have a tmp variable for the current mouse position in X only, then if the mouse moves say 34 pixles left register that as a single left moment and move the block, then reset the tmp variable to this new spot.
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Strange Event.mouseButton.x / y behaviour?
« Reply #1 on: May 14, 2012, 07:44:05 am »
The problem is that you only check if sf::Event::MouseMoved happens. If it does you can obviously use event.mouseMoved.x/y to get the coordinates, but you can't use event.mouseButton.x/y because that event didn't happen.
You can't catch/process two events at the same time.

Also it's often easier to just use the global sf::Mouse object.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything