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

Author Topic: sf::clock dont work inside a class  (Read 4991 times)

0 Members and 1 Guest are viewing this topic.

vengerSC

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
sf::clock dont work inside a class
« on: May 21, 2022, 07:28:00 pm »
I'm triyng to use a sf::clock to compare time and use it as an safety lock for my mouse, it work fine on my main script, but on my class it don't, and i don't know why.
I'm using c++.


Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: sf::clock dont work inside a class
« Reply #1 on: May 21, 2022, 09:00:11 pm »
you are creating a new Clock everytime 'RectOnClick' is called. try moving sf::Clock cl1 outside the RectOnClick function.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

vengerSC

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: sf::clock dont work inside a class
« Reply #2 on: May 21, 2022, 09:16:53 pm »
Your reply give me the "brilliant ideia" to add clock as static and it worked well, thank you.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: sf::clock dont work inside a class
« Reply #3 on: May 21, 2022, 10:05:11 pm »
what!? no, don't need to add it as static (unless, of course, you want many objects from the class to use the same clock). are you used to program in Python or something? it's different in C++
just move the clock outside the funcion, but still inside the class, something like this:

class Rect {

sf::Clock cl1;

public:

        Rect() {}


        void RectOnClick(int Mousex, int Mousey) {
               
                Lemon_Milk.loadFromFile("C:/Users/Felipe Palermo/source/repos/sfmllearn/sfmllearn/LEMONMILK-Bold.otf");

                static int contagem = 1;
                bool LockClick = false;



                if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && LockClick == false) {
//the rest of the code is the same
Visit my game site (and hopefully help funding it? )
Website | IndieDB