Skip to content

Commit 6eb9298

Browse files
committed
Update getContentSize of class Entity.
Check whether it contains a sprite first. If not, set its content size to entity default content size.
1 parent d9cd88a commit 6eb9298

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

BombingAdventure/Classes/Entity.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ void Entity::bind_sprite(Sprite *sprite) {
2020
this->addChild(entity_sprite);
2121

2222
/* Reset the content size and fit the mid-points */
23-
Size entity_size = entity_sprite->getContentSize();
24-
entity_sprite->setPosition(Vec2(entity_size.width * 0.5f, entity_size.height * 0.5f));
25-
this->setContentSize(entity_size);
23+
if(get_sprite() == NULL) {
24+
this->setContentSize(ENTITY_DEFAULT_SIZE);
25+
} else {
26+
Size entity_size = entity_sprite->getContentSize();
27+
entity_sprite->setPosition(Vec2(entity_size.width * 0.5f, entity_size.height * 0.5f));
28+
this->setContentSize(entity_size);
29+
}
2630
}
2731
void Entity::reset_position() {
2832
if(get_sprite() != NULL) {

0 commit comments

Comments
 (0)