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

Author Topic: [SOLVED] RenderWindow disappears immediately  (Read 3243 times)

0 Members and 1 Guest are viewing this topic.

Cakemix

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] RenderWindow disappears immediately
« on: May 07, 2009, 08:57:08 pm »
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:
Code: [Select]
#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:
Code: [Select]
   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!
Code: [Select]
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();
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SOLVED] RenderWindow disappears immediately
« Reply #1 on: May 08, 2009, 12:00:24 pm »
You never call GetEvent.
Laurent Gomila - SFML developer

Cakemix

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] RenderWindow disappears immediately
« Reply #2 on: May 08, 2009, 03:09:41 pm »
Quote from: "Laurent"
You never call GetEvent.


Yeah, that's exactly what I figured out about three hours ago in school.
Of course, there I've had no internet, so I couldn't write it here immediately. ;)

Anyway, thanks alot for your help! :)

(now everything works perfectly fine. I love SFML... :D )

 

anything