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

Author Topic: Weird error [SFML 2.4.2] [screenshot included] [problematic code included]  (Read 1558 times)

0 Members and 1 Guest are viewing this topic.

JamesYeoman

  • Newbie
  • *
  • Posts: 17
    • View Profile
So I was happily coding away and then I realised that I had screwed up somewhere in a constructor (because the build failed)... ok... so I go to the constructor and this happened:


ok... this is ok... I can fix this... (or so I thought)

5 mins later



yeah...

Here is the code

/*
*       Game.cpp
*       Written by James Yeoman
*/


#include "Game.h"

Game::Game(uint16_t windowWidth, uint16_t windowHeight, std::string title)
{
        this->window = sf::RenderWindow(sf::VideoMode(windowWidth, windowHeight), title);
        this->window.setVerticalSyncEnabled(true);
        this->score = 0;
        this->isRoundOver = false;
}

void Game::createEntities()
{
        p1 = Paddle(sf::Vector2f(20, 100), 1);
}

void Game::startLoop()
{
        createEntities();

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
               
                window.clear();
                p1.Update();
                window.draw(p1.getBody());
                window.display();
        }
}

/*
*       Game.h
*       Written by James Yeoman
*/

#pragma once

#include "Paddle.h"
#include "Ball.h"

#include <SFML/Graphics.hpp>

class Game
{
private:
        sf::RenderWindow window;
        uint16_t WindowWidth;
        uint16_t WindowHeight;

        uint8_t score;

        Paddle p1;
        Paddle p2;

        bool isRoundOver;
       
        void createEntities();

public:
        Game(uint16_t, uint16_t, std::string);
        void startLoop();
};
« Last Edit: June 02, 2017, 02:51:36 pm by JamesYeoman »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
this->window.create(...).

Just read the docs next time ;)

Since it's in the constructor, you can also use the initialization list.
Game::Game(...) : window(...)
{
   ...
}
Laurent Gomila - SFML developer

JamesYeoman

  • Newbie
  • *
  • Posts: 17
    • View Profile
this->window.create(...).

Just read the docs next time ;)

Since it's in the constructor, you can also use the initialization list.
Game::Game(...) : window(...)
{
   ...
}

Thanks Laurent. I actually didn't know about initialization lists. When I saw your reply, I went straight to google and looked them up  ;D