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

Author Topic: Making a sf::RenderWindow  (Read 2588 times)

0 Members and 1 Guest are viewing this topic.

DylanMorgan

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Making a sf::RenderWindow
« on: February 16, 2017, 08:28:19 pm »
Hey guys, so I have a game class where I have the private variable
sf::RenderWindow window;
I want to set the windows properties in the constructor of game and then so I can use the window throughout the game class. I will use a getWindow function if I do need to use the window elsewhere. However, I do not understand how to create the window outside of me defining it. I don't know if it is a simple mistake or... Any help is appreciated!

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Making a sf::RenderWindow
« Reply #1 on: February 16, 2017, 09:10:03 pm »
I am not sure if I have understood you correctly, but if you want want to (re)create your window, there's sf::Window::create method dedicated to exactly this purpose.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Making a sf::RenderWindow
« Reply #2 on: February 16, 2017, 09:51:10 pm »
You want to create the window in the constructor of the class instead of at the time of declaring the variable?

You can specify the parameters in the construction of it in the constructor's member initializer list:
class Game
{
public:
    Game();
private:
    sf::RenderWindow window;
}

Game::Game()
    : window(sf::VideoMode(800, 600), "Game")
{
}

or, as sjaustirni said, you can later create the window - or recreate an already-created window - by using window's create() method.
Same example as above but this time using the create method:
class Game
{
public:
    Game();
private:
    sf::RenderWindow window;
}

Game::Game()
{
    window.create(sf::VideoMode(800, 600), "Game");
}
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DylanMorgan

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Making a sf::RenderWindow
« Reply #3 on: February 17, 2017, 06:27:08 pm »
Thank you for the replys guys :) I decided to use the window.create() function