I have a struct "Layer" and class "LayerHandler". Layer consists only a texture, sprite and two constructors - one default and one with a reference parameter. LayerHandler class is a class that handles the drawing of all the layers we have. I add layers to this class and later I use win.draw(layerhandler_object) to draw everything. LayerHandler inherits from Drawable to do so and it overrides virtual void draw().
LayerHandler.h:
#ifndef LAYERHANDLER_H
#define LAYERHANDLER_H
#include <vector>
#include <SFML\Graphics.hpp>
using namespace std;
using namespace sf;
struct Layer {
Texture tex;
Sprite spr;
Layer() { }
Layer(Layer& l) {
tex = l.tex;
spr = l.spr;
}
};
class LayerHandler : public Drawable {
private:
vector<Layer*> layers;
virtual void draw(RenderTarget& target, RenderStates states) const {
for (int i=0; i<layers.size(); i++)
target.draw(layers[i]->spr, states);
}
public:
LayerHandler();
~LayerHandler();
void Add(Layer& layer);
};
#endif
LayerHandler.cpp:
#include "LayerHandler.h"
LayerHandler::LayerHandler() {
}
LayerHandler::~LayerHandler() {
}
void LayerHandler::Add(Layer& layer) {
layers.push_back(new Layer(layer));
}
and main.cpp:
#include <iostream>
#include <SFML\Graphics.hpp>
#include "LayerHandler.h"
using namespace std;
using namespace sf;
int main() {
RenderWindow win(VideoMode(800, 600), "Raven", Style::Default);
win.setFramerateLimit(60);
win.setVerticalSyncEnabled(true);
win.setMouseCursorVisible(false);
LayerHandler lhandler;
Layer back;
back.tex.loadFromFile("bao/gfx/back.png");
back.spr.setTexture(back.tex);
back.spr.setPosition(0, 50);
lhandler.Add(back);
Event evt;
float dt = 0.f;
Clock clock;
float dwticks = clock.getElapsedTime().asMilliseconds();
float dwnewticks = 0.f;
while (win.isOpen()) {
if (win.pollEvent(evt)) {
if (Keyboard::isKeyPressed(Keyboard::Key::Escape)) {
win.close();
}
} else {
dwnewticks = clock.getElapsedTime().asMilliseconds();
dt = dwnewticks > dwticks ? (dwnewticks - dwticks) / 4000.f : 0.f;
dwticks = dwnewticks;
win.clear();
win.draw(lhandler);
win.display();
}
}
return 0;
}
I think it's not complicated and that I did everything ok, but I get this "The value of ESP was not properly saved across the function call" error. I have no idea why I get this error. I know that it may be caused by mismatched calling conventions, but I don't see anything like that in my code... I've got to say that this is the first time ever I got this error and I'm completely out of ideas how to deal with it. Any help?