Hi all,
I'm no expert in C++ but I have experience in other languages with similar syntax, so probably my problem relies only in C++ newbie syndrome.
The problem relies on the fact that I have one window defined as static, that is used from different classes (e.g Intro, Game).
I believe that would be that most logical thing to do, and not defining 1 window for each section/class.
The window is created perfectly and everything goes fine until the next class uses it (1.Intro, 2.Game).
If I don't redefine the window again in the Game class, it will freeze and not render anything to the window.
If I do redefine the window again in the Game class, then it will work, but by creating a new window instance.
Bellow the code I'm using for further analysis, didn't include it all since I don't believe its relevant.
Seriously I'm not trying to "hide" my amazing coding skills
main.cpp
// main.cpp
#include "cCore.h"
int main(){
// Core
::Core Core;
// Initialize game core
if(Core.Initialize()){
::Intro Intro;
if(Intro.Initialize()) Intro.Play();
::Game Game;
if(Game.Initialize()) Game.Play();
} else {
// Core initialization failed
printf("Could not create window!");
}
}
cCore.h
// cCore.h
#ifndef _CCORE_H_
#define _CCORE_H_
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include "globals.h"
(...)
globals.h
// globals.h
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
// Global vars
static enum GameSection {SECTION_INTRO,SECTION_MENU,SECTION_GAME};
static GameSection Section;
static sf::RenderWindow App;
static int screenWidth=640;
static int screenHeight=480;
static int screenDepth=32;
static char *screenTitle="TEST v0.01";
#endif
cIntro.cp
// cIntro.cpp
#include "cCore.h"
// Init game
bool Intro::Initialize(){
::App.Create(sf::VideoMode(::screenWidth,::screenHeight,::screenDepth),::screenTitle);
// Load images
if(!this->imageLogoSadbyte.LoadFromFile("data/images/SadByteLogo.png")) return false;
if(!this->imageLogoXploit.LoadFromFile("data/images/XploitLogo.png")) return false;
// Load sounds
if(!this->sampleSadbyte.LoadFromFile("data/sounds/SadByteBoo.wav")) return false;
this->soundLogo.SetBuffer(sampleSadbyte);
return true;
}
(...)
cGame.cpp
// cGame.cpp
#include "cCore.h"
bool Game::Initialize(){
// Create window
::App.Create(sf::VideoMode(640,480),"Xploit v0.01");
// Load fonts
if(!this->fontVerdanaBold.LoadFromFile("data/fonts/arial.ttf")) return false;
// Load images
if(!this->imageShip.LoadFromFile("data/images/Ship.png")) return false;
this->spriteShip.SetImage(this->imageShip);
return true;
}
(...)