50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
|
#include "versatile_sprite.hpp"
|
||
|
#include "sprite_factory.hpp"
|
||
|
#include "../texture_config.h"
|
||
|
|
||
|
VersatileSprite::VersatileSprite(const std::string &name, sf::Vector2f size)
|
||
|
{
|
||
|
// Try to find in sprites
|
||
|
if (all_sprites.find(name) != all_sprites.end())
|
||
|
{
|
||
|
singleSprite = SpriteFactory::createSingleSprite(name, size);
|
||
|
addChild(singleSprite);
|
||
|
} else if (all_animations.find(name) != all_animations.end())
|
||
|
{
|
||
|
animatedSprite = SpriteFactory::createAnimatedSprite(name, size);
|
||
|
addChild(animatedSprite);
|
||
|
} else
|
||
|
{
|
||
|
LOG(ERROR) << "Sprite " << name << " not found. Could not create versatile sprite.";
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void VersatileSprite::setSize(const sf::Vector2f &size)
|
||
|
{
|
||
|
if (singleSprite != nullptr)
|
||
|
{
|
||
|
singleSprite->setSize(size);
|
||
|
} else if (animatedSprite != nullptr)
|
||
|
{
|
||
|
animatedSprite->setSize(size);
|
||
|
} else
|
||
|
{
|
||
|
Sprite::setSize(size);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sf::Vector2f VersatileSprite::getSize() const
|
||
|
{
|
||
|
if (singleSprite != nullptr)
|
||
|
{
|
||
|
return singleSprite->getSize();
|
||
|
} else if (animatedSprite != nullptr)
|
||
|
{
|
||
|
return animatedSprite->getSize();
|
||
|
} else
|
||
|
{
|
||
|
return Sprite::getSize();
|
||
|
}
|
||
|
}
|