#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
using namespace std;
using namespace sf;
Sprite CreateBall (Image img, Vector2f coords) {
Sprite ball (img);
ball.SetPosition (coords);
return ball;
}
int main () {
RenderWindow window (VideoMode (500, 500, 32), "Squash", Style::Close);
window.SetFramerateLimit (30);
Image imgPaddle;
imgPaddle.LoadFromFile ("paddle.png");
Sprite paddle (imgPaddle);
paddle.SetCenter (paddle.GetSize ().x / 2, 0);
Image imgBall;
imgBall.LoadFromFile ("ball.png");
vector <Sprite*> sprites;
sprites.push_back (&paddle);
int frame = 0;
bool running = true;
while (running) {
Event theEvent;
while (window.GetEvent (theEvent)) {
}
if (frame % 30 == 0) {
Sprite ball = CreateBall (imgBall, Vector2f (window.GetWidth () / 2, window.GetHeight () / 2));
sprites.push_back (&ball);
}
frame++;
window.Clear ();
for (int i = 0; i < sprites.size (); i++) {
window.Draw (*sprites [i]);
}
window.Display ();
}
return 0;
}
The error doesn't occur when I comment out window.Draw. Also if I stop the loop from adding more balls to the vector and instead I add one before the loop starts, it works.
All I know about this error is that I'm trying to call a virtual function from an abstract class or something like that and I don't really know how that is my case.