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

Author Topic: Keeping RenderWindow in a class?  (Read 1110 times)

0 Members and 1 Guest are viewing this topic.

Plazmotech

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Keeping RenderWindow in a class?
« on: May 10, 2013, 03:58:53 am »
How can I keep render window in a class? I have this

//simController.h
class simController {
private:
        sf::RenderWindow game;
public:
    void execute();
    void init();
    void event();
    void exit();
};

and this

//simController.cpp
void simController::init(){
    game = sf::RenderWindow(sf::VideoMode(1280, 920), "Sim");
    game.setFramerateLimit(0);
};

However, RenderWindows are uncopyable, so I cannot do this. I also cannot declare the window directly inside the class. So how can I store a RenderWindow in a class? it seems impossible.

Thanks

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: Keeping RenderWindow in a class?
« Reply #1 on: May 10, 2013, 09:36:48 am »
You can just use the create function.
void simController::init(){
    game.create(sf::VideoMode(1280, 920), "Sim");
    game.setFramerateLimit(0);
};

Or even better, use a constructor instead of an init function in your own class.
simController::simController() :
game(sf::VideoMode(1280, 920), "Sim")
{
    game.setFramerateLimit(0);
};
TGUI: C++ SFML GUI

 

anything