Oczywiście, kod jest dopiero zaczęty, pisałem tylko chwilę i próbowałem włączyć to co napisałem i sprawdzić czy Eventy działają.
Kod:
//initGame.h
#ifndef initGame_h
#define initGame_h
#include <SFML/Graphics.hpp>
sf::RenderWindow wnd(sf::VideoMode(800,600,32),"..."); //nie wiedziałem, gzie to wstawić, może zrobić namespace?
class Menu
{
private:
sf::Event mevent;
public:
bool isMenu;
Menu() { isMenu=true; }
void onMenuEvents();
};
class Game
{
private:
sf::Event event1;
public:
Game() { }
void onGameEvents();
};
#endif
Next:
#include "initGame.h"
void Menu::onMenuEvents()
{
while(wnd.pollEvent(mevent))
{
if(mevent.type==sf::Event::Closed)
wnd.close();
}
}
void Game::onGameEvents()
{
while(wnd.pollEvent(event1))
{
if(event1.type==sf::Event::Closed)
wnd.close();
}
}
Next
#include "initGame.h"
Menu menu;
Game game;
int main()
{
while(wnd.isOpen())//Menu
{
menu.onMenuEvents();
while(menu.isMenu=false)//gra
{
game.onGameEvents();
wnd.display();
}
wnd.display();
}
return 0;
}