Skip to content

SpyderNic/SpriterPlusPlus

 
 

Repository files navigation

SpriterPlusPlus

a C++ Implementation for Spriter animations

About

SpriterPlusPlus aims to be as quick as possible playing back animations, and iterating additional characters once loaded. Additional instances are flyweights that take up less ram than the initially the loaded model. Each flyweight instance minimizes cycles spent in random access and iteratating through containers using stored pointers and iterators wherever possible.

Included example

Sfml for display and sound playback TinyXml for loading

Supported Features

Basic animations Bone animations All curve types (Instant, Linear, Quadratic, Cubic, Quartic, Quintic, Bezier) Points Collision Rectangles SubEntities Events (Triggers) Sounds Variables Tags Character maps

How to use

Extend (All of the following can be found in spriterengine/override) :

FileFactory

and pass to SpriterModel so it can use your own inherited versions of :
  • SpriterFileDocumentWrapper (and Element and Attribute Wrappers) to create parsing code. You can specify a separate SpriterFileDocumentWrapper for scml (xml) and scon (json), which will be automatically selected upon loading based on the file extension
  • ImageFile to store shared texture/image resources to be used by sprite objects
  • SoundFile to store shared sound resources to be used by sound objects, and create your custom extended version of SoundObjectInfoReference to playback and control volume of the shared sound resources

ObjectFactory

and pass to SpriterModel to enable debug rendering:
  • spriterengine/objectinfo/PointObjectInfo

  • spriterengine/objectinfo/BoneInstanceInfo

  • spriterengine/objectinfo/BoxInstanceInfo

  • spriterengine/objectinfo/TriggerObjectInfo if you want to be able to perform a function upon being triggering events

(Alternatively you can query a specific trigger for your instance using :
  • getTriggerObject("triggerName")->getTriggerCount() // in case more than one event was triggered in the elapsed time

Creating an instance :

  • #include "spriterengine/spriterengine.h"

  • ScmlModel scmlModel(fileName, new customFileFactory, new customObjectFactory/optional/);

  • EntityInstance *entityInstance = scmlModel.getNewEntityInstance(entityName or entityIndex);

Controlling playback :

  • entityInstance->setCurrentAnimation(animationName); // defaults to first animation
  • entityInstance->setTimeElapsed(inMilliseconds);
after setting the elapsed Time:
  • entityInstance->render();
and if you're using sound and/or events:
  • entityInstance->playSoundTriggers();
or
  • entityInstance->playEventTriggers();
or
  • entityInstance->playAllTriggers();

Controlling the entire character

  • entityInstance->setPosition(SpriterEngine::point(x,y))
  • entityInstance->setAngle(SpriterEngine::toRadians(angle));
  • entityInstance->setScale(SpriterEngine::point(w,h));

Character Maps

  • entityInstance->applyCharacterMap("charMapOne");
  • entityInstance->applyCharacterMap("charMapTwo");
  • entityInstance->removeCharacterMap("charMapOne");
  • entityInstance->removeAllCharacterMaps();

Metadata

to retrieve a variable from an object :
  • entityInstance->getVariable("objectName","varName")->getRealValue(); // or getIntValue, or getStringValue
to retrieve a variable from the entity itself :
  • entityInstance->getVariable("varName")->getIntValue();
to check if a tag is active :
  • bool myTagIsActive = entityInstance->tagIsActive("objectName", "tagName");
or if the tag is on the entity itself :
  • bool myTagIsActive = entityInstance->tagIsActive("tagName");

TODO:

*Add animation blending *Add helper functions to retrieve a tag or variable and check it's value with one command *Add error handling

Feedback

To provide feedback, report errors, or give suggestions, please use the relevant Spriter forum thread.

About

a C++ implementation to play back Spriter animations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 83.3%
  • C++ 16.1%
  • CSS 0.3%
  • CMake 0.2%
  • GLSL 0.1%
  • JavaScript 0.0%