Hi, I'm learning C++ so I wrote a small class to manage SFML easier :-D
#ifndef ENGINE_H
#define ENGINE_H
#include "global.h"
class Engine
{
public:
Engine(int iWidth, int iHeight, int iBits, const char* sTitle);
void Update(float fTime);
void Delete();
bool GetIsOpened();
virtual ~Engine();
float fElapsedTime;
protected:
private:
sf::RenderWindow App;
sf::Input Input();
sf::Event Event;
sf::Clock Clock;
};
#endif // ENGINE_H
#include "include/Engine.h"
using namespace sf;
Engine::Engine(int iWidth, int iHeight, int iBits, const char* sTitle)
{
RenderWindow App(VideoMode(iWidth, iHeight, iBits), sTitle);
App.SetActive(true);
std::cout << iWidth << iHeight << iBits << sTitle << std::endl;
}
void Engine::Update(float fTime)
{
fElapsedTime += Clock.GetElapsedTime();
Clock.Reset();
while(App.GetEvent(Event))
{
if (Event.Type == Event::Closed || Event.Key.Code == Key::Escape) Engine::Delete();
}
App.Clear();
App.Display();
}
bool Engine::GetIsOpened()
{
return App.IsOpened();
}
void Engine::Delete()
{
App.Close();
}
Engine::~Engine()
{
App.Close();
}
#include "include/global.h"
#include "include/Engine.h"
#define fTIME_STEP 0.01f
#define iWIDTH 1024
#define iHEIGHT 768
#define iBITS 32
#define sTITLE "Panzer-panzer"
using namespace std;
int main()
{
Engine Engine(iWIDTH, iHEIGHT, iBITS, sTITLE);
while (Engine.GetIsOpened())
{
Engine.Update(fTIME_STEP);
}
Engine.~Engine();
system("Pause");
return 0;
}
But I have problem with App.IsOpened() function - it returns 0 (false) causing my game to close just after opening (while(Engine.GetIsOpened)). Why is that?
PS. If you saw any other mistakes in the code - write it here. I'm still learning