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

Author Topic: Error in C++ GetEvent  (Read 3016 times)

0 Members and 1 Guest are viewing this topic.

YoniBE

  • Newbie
  • *
  • Posts: 2
    • View Profile
Error in C++ GetEvent
« 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;
 

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Error in C++ GetEvent
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

YoniBE

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Error in C++ GetEvent
« Reply #2 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Error in C++ GetEvent
« Reply #3 on: June 11, 2013, 12:28:58 pm »
Don't use outdated inofficial tutorials. Use the ones from the official website.
Laurent Gomila - SFML developer

 

anything