Le contexte:
- Avoir plusieurs ecrans differents dans une meme RenderWindow, tres utile pour un jeu ! (splash screen, menu, jeu, options, etc.)
int main()
{
// sfml window
sf::RenderWindow App(sf::VideoMode(800, 600), "Game");
std::vector<Screen*> Screens;
Screens.push_back(new SplashScreen());
int current_screen = SplashScreen::ID;
int temp_screen;
while(current_screen >= 0)
{
// On lance l'affichage
temp_screen = Screens[current_screen]->Run(App);
if(temp_screen != current_screen)
{
current_screen = temp_screen;
}
}
return EXIT_SUCCESS;
}
// SplashScreen
class SplashScreen: public Screen
{
public:
SplashScreen()
{
}
~SplashScreen() {}
int Run (sf::RenderWindow& App);
static const int ID = 0;
};
int SplashScreen::Run(sf::RenderWindow& App)
{
// Splash Screen loading
sf::Texture splash;
if(!splash.loadFromFile("Data/gui/splash/splashscreen.jpg"))
{
exit(0);
}
sf::Sprite spr(splash);
while(App.isOpen()) {
// Clearing out the window
App.clear();
// Event processing.
while(App.pollEvent(m_event) ) {
// If window is about to be closed, leave program.
if(m_event.type == sf::Event::Closed) {
App.close();
}
}
App.draw(spr);
App.display();
}
return -1;
}
Et maintenant, Screen
class Screen
{
public :
Screen() {};
~Screen() {};
virtual int Run (sf::RenderWindow& App) {};
static sf::Event m_event;
static sf::Clock m_clock;
};
Sans le static, j'ai un ecran noir.
J'ajoterais que c'est le meme probleme en ajoutant SFGUI pas en static, ecran noir
voila !
nico