SFML community forums

Help => Window => Topic started by: Pixel_Outlaw on January 30, 2011, 11:01:35 pm

Title: Game engine object "owning" a window?
Post by: Pixel_Outlaw on January 30, 2011, 11:01:35 pm
I'm not sure what to make of these non copyable resources. I'd like my Engine object to own a window and be in charge of that window for the entire duration of the game. I could make the window a global value but this is frowned upon I'm told. Instead I wanted to make an game Engine class that manages resources.

The following code won't work apparently.

Code: [Select]


class Engine
{
    public:
        Engine();
        ~Engine();

        //SFML members
        sf::RenderWindow my_window;
        list<Player> player_list;


};


// methods
Engine::Engine()
{
        my_window = sf::RenderWindow(sf::VideoMode(640, 480, 32), "Assult Match"); // this cannot be assigned

        my_window.Clear(sf::Color(0,255,64));
        my_window.Display();
};

Engine::~Engine()
{

};
Title: Game engine object "owning" a window?
Post by: Grimshaw on January 30, 2011, 11:15:01 pm
my_window.Create() method is the way
Title: Game engine object "owning" a window?
Post by: Pixel_Outlaw on January 30, 2011, 11:58:48 pm
Thanks very much. That seems to have solved the problem.
Title: Game engine object "owning" a window?
Post by: Laurent on January 31, 2011, 07:33:02 am
Or even better:
Code: [Select]
Engine::Engine() :
  my_window(sf::VideoMode(640, 480, 32), "Assult Match")
{
    ...
}