I think somethings wrong with my Game loop. I set everything up as it should be; Clear screen, Draw stuff, Display but it doesn't seem to be working. I'm trying to work with classes, not going so well. It runs, the window opens and clears to white or whatever I set it to.
cbEngine.cpp
#include "cbEngine.h"
cbEngine::cbEngine(int screenWidth, int screenHeight)
: mWindow(sf::VideoMode(screenWidth, screenHeight, 32), "App")
{
}
cbEngine::~cbEngine()
{
//dtor
}
sf::RenderWindow& cbEngine::getWindow()
{
if (runonce == true){
std::cout << "Window Created" << std::endl;
}
return mWindow;
}
sf::Event& cbEngine::getEvent(){
return e;
}
void cbEngine::eventLoop(sf::RenderWindow &window, sf::Event event){
if(runonce == true){
std::cout << "Event Loop Initialized" << std::endl;
}
while(window.pollEvent(event)){
if(event.type == sf::Event::Closed){
window.close();
std::cout << "Window Exited by User." << std::endl;
}
}
}
void cbEngine::runGame(sf::RenderWindow &window){
stateManager sManager; //Create instance of stateManager class
splashScreen splaScreen;
splaScreen.setText();
test.setFillColor(sf::Color::Red);
test.setScale(sf::Vector2f(80,80));
while(window.isOpen()){
if (runonce == true){
std::cout << "Window open" << std::endl;
}
//---Do Only if Debugging---//
// Check to see if runonce is true; if true output to console that game is starting. //
while (debug == true){
if (runonce != false){
std::cout << "Starting game..." << std::endl;
runonce = false;
}
break;
}
// End of Debug Section //
// Loop Structure 1.Clear window (Color = black) 2. Call stateManager 3. Display window //
eventLoop(window, e); // Call event loop Initialize it with window and Event object
window.clear(sf::Color::White); //Clear window black
//sManager.selectState(getWindow());// Section not working WIP
window.draw(test);
window.display(); // Display everything to screen
}
}
cbEngine.h
class cbEngine
{
private:
//Declare Core Variables
sf::RenderWindow mWindow; //Create Base window object
sf::Event e; // Initialize system event object
bool runonce = true; // Boolean for running testing conditions only once (otherwise they'd run non stop alongside window.)
bool debug = 1; //If Debug True certain conditions will be met and testing variables will be output to screen(Exclusive to Engine class)
sf::RectangleShape test; //Rectangleshape test
public:
cbEngine(int screenWidth, int screenHeight); // Initialize Engine with integer screenWidth, screenHeight
virtual ~cbEngine();
//Declare core functions//
//----------------------//
sf::RenderWindow &getWindow(); //Returns main copy of window object
sf::Event &getEvent(); //Returns main copy of event object
void runGame(sf::RenderWindow &window); // Game Loop Runs through logic and displays everything to window
void eventLoop(sf::RenderWindow &window, sf::Event event); //Runs through events
//---End Declaration---//
protected:
private:
};
#endif // CBENGINE_H
#include "includes.h"
int main(){
cbEngine Engine(800, 600);
std::cout << "Main" << std::endl;
Engine.runGame(Engine.getWindow());
return 0;
}