Allowed Sprite size to be optionally set in code (for Cover).
This commit is contained in:
parent
516633a374
commit
99da2acd01
5 changed files with 9 additions and 7 deletions
|
@ -18,9 +18,11 @@ const String Physical::KEY_SIZE = "size";
|
|||
*
|
||||
* @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) {
|
||||
Vector2i size = config.get<Vector2i>(KEY_SIZE);
|
||||
Vector2i size = (pSize == Vector2i())
|
||||
? config.get<Vector2i>(KEY_SIZE)
|
||||
: pSize;
|
||||
assert(size != Vector2i());
|
||||
|
||||
b2BodyDef bodyDef;
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
// Public functions.
|
||||
public:
|
||||
Physical(const PhysicalData& data, const Yaml& config);
|
||||
Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize = Vector2i());
|
||||
virtual ~Physical() = 0;
|
||||
|
||||
Vector2f getPosition() const;
|
||||
|
|
|
@ -17,8 +17,8 @@ const String Sprite::KEY_TEXTURE = "texture";
|
|||
*
|
||||
* @param texturePath Relative path to the texture file in the resource folder.
|
||||
*/
|
||||
Sprite::Sprite(const Yaml& config, const PhysicalData& data) :
|
||||
Physical(data, config),
|
||||
Sprite::Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size) :
|
||||
Physical(data, config, size),
|
||||
mTexture(ResourceManager::i().acquire(Loader::i()
|
||||
.fromFile<sf::Texture>(config.get<String>(KEY_TEXTURE)))),
|
||||
mSize(Vector2i(getSize())) {
|
||||
|
|
|
@ -28,7 +28,7 @@ class Yaml;
|
|||
class Sprite : public sf::Drawable, public Physical {
|
||||
// Public functions.
|
||||
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);
|
||||
virtual ~Sprite() = 0;
|
||||
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
#include "Cover.h"
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue