Well you didn't just change what I suggested, but you changed more.
The player initialization can't be part of the window constructor (closing bracket before the player).
You can't call a function in the initialization list, but you have to use the constructor.
And the initialization list can't have a semicolon at the end.
Game::Game()
: window(sf::VideoMode(800, 600), "02_Game_Archi")
, player(150.f)
{
player.setFillColor(sf::Color::Blue);
player.Position(10.f, 20.f);
}
As you can see in my code, I also recommend to not use using namespace sf; and instead just specifying it. Makes it a lot easier to read the code and see what is an SFML type and what isn't.
(Also I don' think you want a width of 8000 ;) )
I'm sorry to bother you ... i think i fix the problem but the window dont want to stay open!
#include "Game.h"
void Game::run() {
while (window.isOpen()){ //>>>>>>>>>> never get inside this
processEvents();
update();
render();
}
}
Game::Game() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Fast-Typing: The Game",sf::Style::Titlebar);
sf::CircleShape player(150);
player.setFillColor(sf::Color::Blue);
player.setPosition(10, 20);
} ///// the window close after this
Game::~Game() {}
void Game::processEvents() {
while (window.isOpen()) { // main Loop
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
}
}
void Game::update() {
}
void Game::render() {
window.clear(sf::Color::Black);
window.draw(player);
window.display();
}
class Game {
public:
Game();
void run();
virtual ~Game();
public:
void processEvents();
void update();
void render();
sf::RenderWindow window;
sf::CircleShape player;
};
#include <iostream>
#include "Game.h"
using namespace std;
int main() {
Game myGame;
myGame.run();
return 0;
}