Thanks for debugging. Now I see the problem.
The constructor
thor::ParticleSystem::ParticleSystem(std::shared_ptr<const sf::Texture> texture)
looks at the size of the texture and stores it. If the texture is changed later,
thor::ParticleSystem won't recognize the modification and keeps the old size -- in your case (0,0).
Maybe I should document this. To change the behavior, I could poll the texture size (or rect) each frame. But this conflicts with the second constructor
thor::ParticleSystem::ParticleSystem(std::shared_ptr<const sf::Texture> texture, const sf::IntRect& textureRect)
which explicitly stores the specified texture rect. The alternative would be to provide a
setTexture() option, but I actually wanted to set the texture in stone at initialization and leave it for the rest of the lifetime. It looks like the way to go, but I'm sure if I don't enforce to pass it in the constructor, people will forget to pass a texture again and again. However, they should already know from
sf::Sprite shared_ptr is misleading at this place in Thor, it suggests that you can alter the texture after passing it to the particle system. I don't know whether it's a good idea to use it here anyway. The user needn't care about ownership anymore, but he is forced to use also
shared_ptr in his code (even if it's only a function that sets the shared pointer to an automatic variable). And since he must own the textures for SFML's sprite anyway, I could handle particle systems similarly, i.e. the constructor may in future take:
thor::ParticleSystem::ParticleSystem(const sf::Texture& texture);
I still have to think about this, it's also a point on my
progress list.
For the moment, you have to initialize the texture before passing it to the particle system. You can do it like this:
std::shared_ptr<sf::Texture> createTexture()
{
// instead of
// std::shared_ptr<sf::Texture> texture(new sf::Texture());
auto texture = std::make_shared<sf::Texture>();
if (!texture->loadFromFile("particle.png"))
{
// error
}
return texture;
}
Particle::Particle()
: emitter(thor::UniversalEmitter::create())
, texture(createTexture())
, system(texture)
, fader(0.1f, 0.1f)
{
...
}
But I have to do something in the long term. Thanks for pointing this out!