Allowed Sprite size to be optionally set in code (for Cover).

This commit is contained in:
Felix Ableitner 2012-10-13 12:54:09 +02:00
parent 516633a374
commit 99da2acd01
5 changed files with 9 additions and 7 deletions

View file

@ -18,9 +18,11 @@ const String Physical::KEY_SIZE = "size";
* *
* @param data Data needed for construction. * @param data Data needed for construction.
*/ */
Physical::Physical(const PhysicalData& data, const Yaml& config) : Physical::Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize) :
mDelete(false) { mDelete(false) {
Vector2i size = config.get<Vector2i>(KEY_SIZE); Vector2i size = (pSize == Vector2i())
? config.get<Vector2i>(KEY_SIZE)
: pSize;
assert(size != Vector2i()); assert(size != Vector2i());
b2BodyDef bodyDef; b2BodyDef bodyDef;

View file

@ -73,7 +73,7 @@ public:
// Public functions. // Public functions.
public: public:
Physical(const PhysicalData& data, const Yaml& config); Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize = Vector2i());
virtual ~Physical() = 0; virtual ~Physical() = 0;
Vector2f getPosition() const; Vector2f getPosition() const;

View file

@ -17,8 +17,8 @@ const String Sprite::KEY_TEXTURE = "texture";
* *
* @param texturePath Relative path to the texture file in the resource folder. * @param texturePath Relative path to the texture file in the resource folder.
*/ */
Sprite::Sprite(const Yaml& config, const PhysicalData& data) : Sprite::Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size) :
Physical(data, config), Physical(data, config, size),
mTexture(ResourceManager::i().acquire(Loader::i() mTexture(ResourceManager::i().acquire(Loader::i()
.fromFile<sf::Texture>(config.get<String>(KEY_TEXTURE)))), .fromFile<sf::Texture>(config.get<String>(KEY_TEXTURE)))),
mSize(Vector2i(getSize())) { mSize(Vector2i(getSize())) {

View file

@ -28,7 +28,7 @@ class Yaml;
class Sprite : public sf::Drawable, public Physical { class Sprite : public sf::Drawable, public Physical {
// Public functions. // Public functions.
public: public:
Sprite(const Yaml& config, const PhysicalData& data); Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size = Vector2i());
Sprite(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data); Sprite(const std::shared_ptr<sf::Texture>& texture, const PhysicalData& data);
virtual ~Sprite() = 0; virtual ~Sprite() = 0;

View file

@ -8,6 +8,6 @@
#include "Cover.h" #include "Cover.h"
Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) : Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) :
Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false)) { Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) {
} }