Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added interface to access calculated animation bounds. #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion spriterengine/animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace SpriterEngine
std::string getName();
real getLength();
bool getIsLooping();

point getBoundsPosition() const { return boundsPosition; }
void setBoundsPosition(point position) { boundsPosition = position; }
point getBoundsSize() const { return boundsSize; }
void setBoundsSize(point size) { boundsSize = size; }

void setupAnimationInstance(EntityInstance *entityInstance, EntityInstanceData *entityInstanceData, MainlineKeyInstanceVector *mainlineKeyInstances, TimelineInstanceVector *timelineInstances, real *length, bool *looping);

Expand All @@ -58,7 +63,9 @@ namespace SpriterEngine
TimelineVector tagTimelines;
TimelineVector soundTimelines;
TimelineVector triggerTimelines;


point boundsPosition;
point boundsSize;
real animationLength;
bool isLooping;
};
Expand Down
7 changes: 6 additions & 1 deletion spriterengine/entity/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ namespace SpriterEngine
entityInstanceData->setTagInstance(THIS_ENTITY, "");
setupAnimationInstances(entityInstance, entityInstanceData);
}


AnimationVector* Entity::getAnimations()
{
return &animations;
}

Object *Entity::setObject(std::string objectName, Object::ObjectType objectType)
{
switch (objectType)
Expand Down
1 change: 1 addition & 0 deletions spriterengine/entity/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace SpriterEngine
EntityInstance *getNewEntityInstance(SpriterModel *model, ObjectFactory *objectFactory);
void setupInstance(SpriterModel *model, EntityInstance *entityInstance, EntityInstanceData *entityInstanceData, ObjectFactory *objectFactory);

AnimationVector* getAnimations();
Animation *pushBackAnimation(std::string animationName, real length, bool looping);

Object *setObject(std::string objectName, Object::ObjectType objectType);
Expand Down
20 changes: 18 additions & 2 deletions spriterengine/loading/spriterdocumentloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ namespace SpriterEngine

Animation *SpriterDocumentLoader::getNewAnimationFromAnimationElement(SpriterFileElementWrapper *animationElement, Entity *entity)
{
Animation *newAnimation = 0;
real animationLength = 0;
bool animationLooping = true;
SpriterFileAttributeWrapper *att = animationElement->getFirstAttribute("name");
SpriterFileAttributeWrapper *att2 = nullptr;
if (att->isValid())
{
std::string animationName = att->getStringValue();
Expand All @@ -724,7 +724,23 @@ namespace SpriterEngine
animationLooping = att->getStringValue() != "false";
}

return entity->pushBackAnimation(animationName, animationLength, animationLooping);
Animation *newAnimation = entity->pushBackAnimation(animationName, animationLength, animationLooping);
att = animationElement->getFirstAttribute("l");
att2 = animationElement->getFirstAttribute("t");
if (att->isValid() && att2->isValid())
{
real l = att->getRealValue(), t = att2->getRealValue();
newAnimation->setBoundsPosition({ l, t });

att = animationElement->getFirstAttribute("r");
att2 = animationElement->getFirstAttribute("b");
if (att->isValid() && att2->isValid())
{
real r = att->getRealValue(), b = att2->getRealValue();
newAnimation->setBoundsSize({ r - l, b - t });
}
}
return newAnimation;
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions spriterengine/model/spritermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ namespace SpriterEngine
fileReferences->push_back(new FileReference(it));
}
}

EntityVector* SpriterModel::getEntities()
{
return &entities;
}

Entity *SpriterModel::pushBackEntity(std::string entityName)
{
Expand Down
1 change: 1 addition & 0 deletions spriterengine/model/spritermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace SpriterEngine
void appendEntityToInstanceByName(EntityInstance * entityInstance, std::string entityName);
void setupFileReferences(FileReferenceVector *fileReferences);

EntityVector* getEntities();
Entity *pushBackEntity(std::string entityName);
void pushBackImageFile(std::string initialFilePath, point initialDefaultPivot, atlasdata atlasData);
void pushBackSoundFile(std::string initialFilePath);
Expand Down