Hey there. I hope a problem like mine really wasn't already here...
(I tried to find it with the search-thing here)
Now: I'm trying to make a little game with SFML. The problem I have here is that my own class, which is a "child" (or derived?) of the sf::RenderWindow class, causes a problem.
So this class (which is called "MenuInterface") has all the stuff which RenderWindow has and additionally some Attributes and Operations, e.g. Sprites and Images, which are usefull in the MainMenu of my game.
Everything compiles etc., but then the window appears for a very short time (less than sec.. just flashes) and disappears.
I don't have any idea why this is happenning and I hope someone out there is able to help me. (since I'm not that experienced with SFML, the mistake may lay somewhere, I would never expect it...)
Here are some parts of my code:
Class definition:#include "Point.h"
#include "SFML/Graphics.hpp"
class Interface;
/********************************************************************
* Is the window for the main menu. As well loads images and displays
* the sprites needed in the main menu.
********************************************************************/
class MenuInterface: public sf::RenderWindow
{
private:
sf::Image *imgMenu[3];
sf::Sprite *sprMenu[3];
int maxSprMenuID;
sf::Event myEvent; //needed to respond on the user's actions
Interface *myInterface; //needed to change the Interface's mode
Point mousePos;
//-------OPERATIONS:-----------------------------------------
void initImages(); //loads all picture needed for the menu
void initSprites(); //sets the position etc. of the sprites
bool mouseOverSprite(int pSprMenuID);
public:
MenuInterface(Interface *pInterface);
float tick(); //does everything which is needed and returns frameTime
};
And the implementation of the function "tick", which can be seen as the main-function.
This function gets called by another class in a while-loop, untill the program exits.
The lines:
std::cout << "Frame gezeichnet." << std::endl;
std::cout << GetFrameTime() << std::endl;
are used for debugging and my debug-console is spammed with those couts all the time. So even then, when the window seems to have dissappeared.
Now the whole code of tick!float MenuInterface::tick()
{
switch(myEvent.Type)
{
case sf::Event::Closed: //On window closed:
Close(); //close it
// myInterface->setMode(-1); //set new mode
break;
case sf::Event::MouseMoved:
mousePos.x = myEvent.MouseMove.X; //Set new mousePos
mousePos.y = myEvent.MouseMove.Y;
break;
case sf::Event::MouseButtonReleased:
//Maus über dem Button Start?
if(mouseOverSprite(1))
{
Close();
myInterface->setMode(1);
}
break;
}
//clear and redraw everything:
Clear(sf::Color(0,0,0,0));
for(int i = 0; i <= maxSprMenuID; i++)
{
Draw(*sprMenu[i]);
}
Display();
std::cout << "Frame gezeichnet." << std::endl;
std::cout << GetFrameTime() << std::endl;
return GetFrameTime();
}