Hello,
I'm programming an ECS in C++ and wanted to integrate SFML into it.
I save my components invoid pointer and save the corrisponding class information with it.
When I cast the void pointer backt to sf::Transformable, my calls will be mostly ignored(?) or simpy have no impact on the object.
I have created an example outside my ECS to illustrate the issue:
#include <SFML/Graphics.hpp>
int main() {
{
sf::CircleShape* cs = new sf::CircleShape(50);
cs->setFillColor(sf::Color::Green);
void* t = cs;
void* d = cs;
sf::RenderWindow window(sf::VideoMode(640, 640), "SFML Test");
// game loop
while (window.isOpen()) {
// events
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
default:
break;
}
}
static_cast<sf::Transformable*>(t)->move(0.1, 0.1);
window.clear();
window.draw(*static_cast<sf::Drawable*>(d));
window.display();
}
delete cs;
}
return 0;
}
When this code is executed, the circle will only move once.
When I replace the void* t = cs; with sf::Transformable* t = cs;, everything works just fine and as expected (The circle moves offscreen.).
I'm curious if I'm missing something specific inside SFML, because the same approach works with other classes and examples.
So why won't the circle move in each iteration?
Normally I would ask this in a Cpp only forum, but I can't replicate the problem in other libraries or construct a similar example.
I'm using Windows 10 and Visual Studio 2015.