Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <SFML/Window.hpp>
- class Game
- {
- public:
- // Access for getting singleton reference
- static Game& GetInstance()
- {
- static Game game;
- return game;
- };
- // Public member functions
- void Start()
- {
- m_window.create(sf::VideoMode(800, 600), "MyNetGame");
- sf::Font font;
- font.loadFromFile("sheets/DroidSansMono.ttf");
- sf::Text * p_connectText = new sf::Text("test", font);
- p_connectText->setColor(sf::Color::Yellow);
- sf::FloatRect textRect = p_connectText->getLocalBounds();
- p_connectText->setOrigin(textRect.left+textRect.width/2.0f,
- textRect.top+textRect.height/2.0f);
- p_connectText->setPosition(100, 100);
- m_p_text = p_connectText;
- };
- void Loop()
- {
- while (m_window.isOpen())
- {
- sf::Event event;
- while (m_window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- m_window.close();
- }
- m_window.clear();
- m_window.draw(*m_p_text);
- m_window.display();
- }
- };
- private:
- // Hidden singleton/copy/assignment constructors
- Game()
- {};
- Game(const Game&)
- {};
- const Game& operator=(const Game&)
- {};
- // Member variables
- sf::Text * m_p_text;
- sf::RenderWindow m_window;
- };
- // Program entry point
- int main(int argc, char** argv)
- {
- Game::GetInstance().Start();
- Game::GetInstance().Loop();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement