#include <iostream>
#include "Game.h"
using namespace std;
int main() {
//Init Game Engine
Game game;
//Game loop
while (game.running())
{
//Update
game.update();
//Render
game.render();
}
//End of application
return 0;
}
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
/*
Class that acts as the game engine.
Wrapper class.
*/
class Game
{
public:
//Constructors / Destructors
Game();
virtual ~Game();
//Accessors
const bool running() const;
//Functions
void pollEvents();
void update();
void render();
private:
//Variables
//Window
sf::RenderWindow* window;
sf::VideoMode videoMode;
sf::Event ev;
//Private functions
void initVariables();
void initWindow();
};
#include "Game.h"
//Constructors / Destructors
Game::Game()
{
this->initVariables();
this->initWindow();
}
Game::~Game()
{
delete this->window;
}
const bool Game::running() const
{
return this->window->isOpen(); [this is where I'm getting the error]
}
//Functions
void Game::pollEvents()
{
//Event polling
while (this->window->pollEvent(this->ev))
{
switch (this->ev.type)
{
case sf::Event::Closed:
this->window->close();
break;
case sf::Event::KeyPressed:
if (this->ev.key.code == sf::Keyboard::Escape)
this->window->close();
break;
}
}
}
void Game::update()
{
this->pollEvents();
}
void Game::render()
{
/*
@return void
- clear old frame
- render objects
- display frame in window
Renders the game objects.
*/
this->window->clear(sf::Color(255, 0, 0, 255));
//Draw game objects
this->window->display();
}
//Private functions
void Game::initVariables()
{
this->window == nullptr;
}
void Game::initWindow()
{
this->videoMode.height = 600;
this->videoMode.width = 800;
this->window == new sf::RenderWindow(this->videoMode, "Game 1", sf::Style::Titlebar | sf::Style::Close);
}
Hello == is comparison not assign. ChangeThank you so much! This fixed it.this->window == new sf::RenderWindow(this->videoMode, "Game 1", sf::Style::Titlebar | sf::Style::Close);tothis->window = new sf::RenderWindow(this->videoMode, "Game 1", sf::Style::Titlebar | sf::Style::Close);