The Sprite class is not default constructable because the Texture reference must always be initialised to a value. The most flexible fix is to add a default constructor to the Sprite class.
Either turn the texture reference into a pointer and initialise it to nullptr, and update the existing constructor accordingly:
Sprite()
: m_texture(nullptr)
{
}
Sprite(sf::Texture& tx, sf::IntRect rect, sf::Vector2f size)
: m_texture(&tx), m_sprite(tx)
{
m_sprite.setTextureRect(rect);
original_size = m_texture->getSize();
texture_size.x = static_cast<float>(original_size.x);
texture_size.y = static_cast<float>(original_size.y);
sprite_scale.x = size.x / texture_size.x;
sprite_scale.y = size.y / texture_size.y;
m_sprite.setScale(sf::Vector2f(sprite_scale.x, sprite_scale.y));
m_sprite.setOrigin(sf::Vector2f(original_size.x / 2, original_size.y / 2));
}
Or remove the texture member completely. As I mentioned in a previous post, sf::Sprite can be used to handle the texture reference.
Sprite()
{
}
Sprite(sf::Texture& tx, sf::IntRect rect, sf::Vector2f size)
: m_sprite(tx)
{
m_sprite.setTextureRect(rect);
original_size = m_sprite.getTexture()->getSize();
texture_size.x = static_cast<float>(original_size.x);
texture_size.y = static_cast<float>(original_size.y);
sprite_scale.x = size.x / texture_size.x;
sprite_scale.y = size.y / texture_size.y;
m_sprite.setScale(sf::Vector2f(sprite_scale.x, sprite_scale.y));
m_sprite.setOrigin(sf::Vector2f(original_size.x / 2, original_size.y / 2));
}
HOWEVER from your entity constructor it looks like you're using the Sprite class to initialise and resize an sf::Sprite, which is then stored as a member of the Entity class. In which case why not use a simple function to set up your sprites?
sf::Sprite initSprite(sf::Texture& t, sf::IntRect rect, sf::Vector2f size)
{
sf::Sprite sprite(t);
sprite.setTextureRect(rect);
sf::Vector2f texture_size(t.getSize());
sprite.setScale(size.x / texture_size.x, size.y / texture_size.y );
sprite.setOrigin(texture_size / 2.f);
return sprite;
}
Entity()
{
entity_sprite = initSprite(AssetManager::LoadTexture("res/wildcard.png"), sf::IntRect(0, 0, 36, 63), { 36,63 });
}
You're quite right to try avoiding globals, particularly with SFML types as SFML maintains its own global state which may get messed up. Using an asset manager implemented as a singleton probably constitutes global access, however