SFML community forums

Help => Graphics => Topic started by: YoniBE on June 11, 2013, 07:19:35 am

Title: Error in C++ GetEvent
Post by: YoniBE on June 11, 2013, 07:19:35 am
Hi! :)
I started to build a simple computer game (in 2D) with C++ and SFML.
And I got this error:
Error 1 error C2039: 'GetEvent' : is not a member of 'sf::RenderWindow'
Someone can explain me what I wrote wrong?

(the error in game.cpp where I wrote "//her the error"
This is my files:

game.h
#pragma once
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"


class Game
{
public:
    static void Start();


private:
    static bool IsExiting();
    static void GameLoop();


    enum GameState { Uninitialized, ShowingSplash, Paused, ShowingMenu, Playing, Exiting };


    static GameState _gameState;
    static sf::RenderWindow _mainWindow;


};
 

game.cpp
#include "stdafx.h"
#include "Game.h"




void Game::Start(void)
{
    if(_gameState != Uninitialized)
    {
        return;
    }


    _mainWindow.create(sf::VideoMode(1024, 768, 32), "Pang!");
    _gameState = Game::Playing;


    while(!IsExiting())
    {
        GameLoop();
    }


    _mainWindow.close();
}


bool Game::IsExiting()
{
    if(_gameState == Game::Exiting)
    {
        return true;
    }
    else
    {
        return false;
    }
}


void Game::GameLoop()
{
    sf::Event currentEvent;
 while(_mainWindow.GetEvent(currentEvent))  //her the error
    {


        switch(_gameState)
        {
        case Game::Playing:
            {
                _mainWindow.clear(sf::color(255,0,0));
                _mainWindow.Display();


                if(currentEvent.type == sf::Event::Closed)
                {
                    _gameState = Game::Exiting;
                }
                break;
            }
        }
    }
}


Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_mainWindow;
 
Title: Re: Error in C++ GetEvent
Post by: Nexus on June 11, 2013, 09:34:12 am
Isn't the error message clear enough? sf::RenderWindow has no method GetEvent() in SFML 2.0, this was in SFML 1.6. Please read the tutorials and documentation of SFML 2 to know how to work with it.

And don't use static variables for the game state and the SFML window, you'll just get problems with initialization and destruction order of SFML internals.
Title: Re: Error in C++ GetEvent
Post by: YoniBE on June 11, 2013, 12:19:14 pm
Isn't the error message clear enough? sf::RenderWindow has no method GetEvent() in SFML 2.0, this was in SFML 1.6. Please read the tutorials and documentation of SFML 2 to know how to work with it.

And don't use static variables for the game state and the SFML window, you'll just get problems with initialization and destruction order of SFML internals.

Thanks for help, I use this tutorial:
http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-2.aspx
Title: Re: Error in C++ GetEvent
Post by: Laurent on June 11, 2013, 12:28:58 pm
Don't use outdated inofficial tutorials. Use the ones from the official website.