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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Catalin_Cristian

Pages: [1]
1
General / Drawing text with a class
« on: April 28, 2018, 06:33:32 pm »
Hi guys, I tried to render a text and I got this error:  sf::RenderTarget::draw': no overloaded function takes 0 arguments.

This is the code:

the class:

class menu
{
public:
   void draw_text();
   void move_up();
   void move_down();


private:

   sf::Text text;
   sf::Font font;
};

menu cpp:

void menu::draw_text()
{
   try {

      if (!font.loadFromFile("champ.ttf"))
         throw font.loadFromFile("champ.ttf");
   }
   catch (...) {
      cout << "Error! Missing font!";
   }

   text.setFont(font);
   text.setFillColor(sf::Color::Red);
   text.setString("Hello there");
        text.setCharacterSize(30);
       
}


the main cpp:

int main()
{
   menu menuObj;

   sf::RenderWindow window(sf::VideoMode(1920, 1080), "SpaceShooter");

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

      window.clear();
      window.draw();
                menuObj.draw_text();
      window.display();
   }

   return 0;
}


I didn't finish the text code but I tried it to see if it works, to see if at least the text appears on screen.I don't know if you will understand the code but I hope someone can help me.

Pages: [1]