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

Author Topic: How does MouseMoveEvent work exactly?  (Read 2713 times)

0 Members and 1 Guest are viewing this topic.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
How does MouseMoveEvent work exactly?
« on: June 11, 2013, 02:58:32 pm »
In my continuous mission of making more interactive stuff I'm having some difficulty understanding the way MouseMoveEvent works and I know this is what I'll need if I want to make things like buttons etc. I've been trying the usual methods other code uses but of course that isn't working.

Does anyone have know of any source code examples and such that show a basic button working for example? What I'm trying to do is to get the code to detect my mouse going over a sprite and then replacing it with another sprite when I click for example. I bet it's going to be one of those things where it just has a specific way of working to the other input commands and I've missed it completely.

Just so you know, I have looked at the documentation but of course it only explains the syntax and doesn't show it actually being used in a practical way which I think is why I'm having trouble understanding it.
« Last Edit: June 11, 2013, 03:02:23 pm by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: How does MouseMoveEvent work exactly?
« Reply #1 on: June 11, 2013, 03:10:14 pm »
Well now I feel stupid this section had exactly what I needed.

http://www.sfml-dev.org/tutorials/2.0/window-events.php

Just a quick question though, would the syntax be the same if I were to say replace cout with my sprite class?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How does MouseMoveEvent work exactly?
« Reply #2 on: June 11, 2013, 03:24:44 pm »
Quote
would the syntax be the same if I were to say replace cout with my sprite class?
Of course.
Laurent Gomila - SFML developer

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: How does MouseMoveEvent work exactly?
« Reply #3 on: June 11, 2013, 03:29:19 pm »
Yey! In that case I can experiment more now :) thanks for the help.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: How does MouseMoveEvent work exactly?
« Reply #4 on: June 11, 2013, 07:29:07 pm »
>_< :(

Quote


    while (window.isOpen())
    {

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

if ( event.type == sf::Event::mouseMove );

{
    std::cout << "Mouse Move X works!: " << event.mouseMove.x;
    std::cout << "Mouse Move Y works!: " << event.mouseMove.y;
}


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

        window.clear();
        window.display();

    }

    return 0;

}



Quote
error: invalid use of non-static data member 'sf::Event::<anonymous union>::mouseMove'

I'm a bit baffled by this error message, it seems to be complaining about the classes? Not quite sure about this one the problem is when I tried changing "event" it threw up scope error messages instead, I've tried using MouseMoveEvent instead but of course that just caused more problems.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: How does MouseMoveEvent work exactly?
« Reply #5 on: June 11, 2013, 07:39:30 pm »
wow just got it sort of working! nevermind, for some reason the IDE at first didn't like it very much when I used MouseMoved then when I fiddled around some more it did.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How does MouseMoveEvent work exactly?
« Reply #6 on: June 11, 2013, 08:51:14 pm »
Trust the official documentation, not the buggy intellisense of your IDE.
Laurent Gomila - SFML developer

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: How does MouseMoveEvent work exactly?
« Reply #7 on: June 11, 2013, 09:58:58 pm »
lol I'm using codeblocks and it does some weird ass things sometimes but I guess this must be something you have to get used to when programming.

 

anything