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

Author Topic: How do I use sf::Event in a class  (Read 2763 times)

0 Members and 2 Guests are viewing this topic.

Alidro

  • Newbie
  • *
  • Posts: 18
    • View Profile
How do I use sf::Event in a class
« on: July 18, 2017, 07:55:32 pm »
Hello,
I am pretty sure there is a solution easy to find to this if I were better at the C++ in General but  I'm not.
I wanted to create a class, which contains text input. I wanted to do this with sf::Event::TextEntered but i dont know how to use it in a class since i am not able to use my sf::Event there because i declared it in main(). I dont have any code to post here because i have absolutely no idea.
I did not find anything useful for me in the Documentation.

Thank you for every good advice.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How do I use sf::Event in a class
« Reply #1 on: July 18, 2017, 10:52:59 pm »
You can simply pass the event to the class as a parameter and then use it inside the class.
e.g.
class SomeClass
{
public:
    void passAnEventToThisClass(sf::Event event)
    {
        if (event.type == sf::Event::Closed)
            std::cout << "This class realised that close was requested.\n";
    }
};
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Alidro

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: How do I use sf::Event in a class
« Reply #2 on: July 18, 2017, 11:28:16 pm »
Thank you, thats all i wanted to know.
Im kind of embarrassed that i didnt get this easy solution by myself but anyway thanks.

 

anything