Fixed wrong order initialization.

This commit is contained in:
Felix Ableitner 2013-04-04 21:50:52 +02:00
parent 3d9ab86e72
commit 7ebf912aad

View file

@ -28,24 +28,7 @@ Sprite::Sprite(const Data& data, const Yaml& config) :
mCategory(data.category), mCategory(data.category),
mMask(data.mask), mMask(data.mask),
mDelete(false) { mDelete(false) {
std::string texture = config.get<std::string>(KEY_TEXTURE, ""); // Init shape
if (texture != "") {
try {
mTexture = ResourceManager::i().acquire(Loader::i()
.fromFile<sf::Texture>(texture));
mShape.shape->setTexture(&*mTexture, false);
}
catch (thor::ResourceLoadingException&) {
LOG_W("Failed to load texture " << texture << ", coloring red.");
mShape.shape->setFillColor(sf::Color(255, 0, 0));
}
}
else {
LOG_W("Failed to read texture file name from YAML file " <<
config.getFilename() << ", coloring red.");
mShape.shape->setFillColor(sf::Color(255, 0, 0));
}
float radius = config.get(KEY_RADIUS, 0.0f); float radius = config.get(KEY_RADIUS, 0.0f);
sf::Vector2f size = config.get(KEY_SIZE, sf::Vector2f()); sf::Vector2f size = config.get(KEY_SIZE, sf::Vector2f());
if (radius != 0.0f) { if (radius != 0.0f) {
@ -67,6 +50,25 @@ Sprite::Sprite(const Data& data, const Yaml& config) :
mShape.shape->setTextureRect(sf::IntRect(sf::Vector2i(0, 0), sf::Vector2i(size))); mShape.shape->setTextureRect(sf::IntRect(sf::Vector2i(0, 0), sf::Vector2i(size)));
} }
// Init texture
std::string texture = config.get<std::string>(KEY_TEXTURE, "");
if (texture != "") {
try {
mTexture = ResourceManager::i().acquire(Loader::i()
.fromFile<sf::Texture>(texture));
mShape.shape->setTexture(&*mTexture, false);
}
catch (thor::ResourceLoadingException&) {
LOG_W("Failed to load texture " << texture << ", coloring red.");
mShape.shape->setFillColor(sf::Color(255, 0, 0));
}
}
else {
LOG_W("Failed to read texture file name from YAML file " <<
config.getFilename() << ", coloring red.");
mShape.shape->setFillColor(sf::Color(255, 0, 0));
}
setPosition(data.position); setPosition(data.position);
setDirection(data.direction); setDirection(data.direction);
} }