I don't know if this is a C++ question or an SFML question but what exactly is happening here in this constructor. I've never seen a constructor written like this before and I can't find any other examples online.
Rather than using opening braces, it starts with a semi-colon, and why comma's after texture, player, font, etc? If Texture is a member variable why is there a ()?
Game::Game()
: Window(sf::VideoMode(Resolution.x, Resolution.y), "SFML Application", sf::Style::Close)
, Texture()
, Player()
, Font()
, isMovingUp(false)
, isMovingDown(false)
, isMovingRight(false)
, isMovingLeft(false) {
if (!Texture.loadFromFile("Graphics/character.png")) {
// loading error
}
Player.setTexture(Texture);
Player.setPosition(100.f, 100.f);
}
Why can't I get the constructor to work like this?
Game::Game() {
Window(VideoMode(Resolution.x, Resolution.y), "SFML Application", sf::Style::Close);
isMovingUp = false;
isMovingDown = false;
isMovingRight = false;
isMovingLeft = false;
if (!Texture.loadFromFile("Graphics/character.png")) {
// loading error
}
Player.setTexture(Texture);
Player.setPosition(100.f, 100.f);
}
}