mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
[c] Closes #2401, fixed incorrect allocation of TransformTimeline.
This commit is contained in:
parent
5989c861ca
commit
c960402c08
@ -1144,7 +1144,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
|
|||||||
TransformConstraintData *constraint = skeletonData->findTransformConstraint(constraintMap->_name);
|
TransformConstraintData *constraint = skeletonData->findTransformConstraint(constraintMap->_name);
|
||||||
int constraintIndex = skeletonData->_transformConstraints.indexOf(constraint);
|
int constraintIndex = skeletonData->_transformConstraints.indexOf(constraint);
|
||||||
TransformConstraintTimeline *timeline = new (__FILE__, __LINE__) TransformConstraintTimeline(
|
TransformConstraintTimeline *timeline = new (__FILE__, __LINE__) TransformConstraintTimeline(
|
||||||
constraintMap->_size, constraintMap->_size << 2, constraintIndex);
|
constraintMap->_size, constraintMap->_size * 6, constraintIndex);
|
||||||
|
|
||||||
float time = Json::getFloat(keyMap, "time", 0);
|
float time = Json::getFloat(keyMap, "time", 0);
|
||||||
float mixRotate = Json::getFloat(keyMap, "mixRotate", 1);
|
float mixRotate = Json::getFloat(keyMap, "mixRotate", 1);
|
||||||
|
|||||||
@ -33,27 +33,78 @@
|
|||||||
|
|
||||||
using namespace spine;
|
using namespace spine;
|
||||||
|
|
||||||
|
class NullTextureLoader : public TextureLoader {
|
||||||
|
public:
|
||||||
|
virtual void load(AtlasPage &page, const String &path) {}
|
||||||
|
|
||||||
|
virtual void unload(void *texture) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class NullAttachmentLoader : public AttachmentLoader {
|
||||||
|
virtual RegionAttachment *newRegionAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) {
|
||||||
|
return new (__FILE__, __LINE__) RegionAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual MeshAttachment *newMeshAttachment(Skin &skin, const String &name, const String &path, Sequence *sequence) {
|
||||||
|
return new (__FILE__, __LINE__) MeshAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual BoundingBoxAttachment *newBoundingBoxAttachment(Skin &skin, const String &name) {
|
||||||
|
return new (__FILE__, __LINE__) BoundingBoxAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual PathAttachment *newPathAttachment(Skin &skin, const String &name) {
|
||||||
|
return new (__FILE__, __LINE__) PathAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual PointAttachment *newPointAttachment(Skin &skin, const String &name) {
|
||||||
|
return new (__FILE__, __LINE__) PointAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ClippingAttachment *newClippingAttachment(Skin &skin, const String &name) {
|
||||||
|
return new (__FILE__, __LINE__) ClippingAttachment(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void configureAttachment(Attachment *attachment) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
String atlasFile("data/spineboy-pma.atlas");
|
String atlasFile("");
|
||||||
String skeletonFile("data/spineboy-pro.skel");
|
String skeletonFile("/Users/badlogic/Downloads/catsanddogs2.json");
|
||||||
|
String animation = "";
|
||||||
|
|
||||||
float scale = 0.6f;
|
float scale = 0.6f;
|
||||||
SFMLTextureLoader textureLoader;
|
SFMLTextureLoader textureLoader;
|
||||||
Atlas *atlas = new Atlas(atlasFile, &textureLoader);
|
NullAttachmentLoader nullLoader;
|
||||||
|
Atlas *atlas = atlasFile.length() == 0 ? nullptr : new Atlas(atlasFile, &textureLoader);
|
||||||
SkeletonData *skeletonData = nullptr;
|
SkeletonData *skeletonData = nullptr;
|
||||||
if (strncmp(skeletonFile.buffer(), ".skel", skeletonFile.length()) > 0) {
|
if (strnstr(skeletonFile.buffer(), ".skel", skeletonFile.length()) != nullptr) {
|
||||||
SkeletonBinary binary(atlas);
|
SkeletonBinary *binary = nullptr;
|
||||||
binary.setScale(scale);
|
if (atlas) {
|
||||||
skeletonData = binary.readSkeletonDataFile(skeletonFile);
|
binary = new SkeletonBinary(atlas);
|
||||||
} else {
|
} else {
|
||||||
SkeletonJson json(atlas);
|
binary = new SkeletonBinary(&nullLoader);
|
||||||
json.setScale(scale);
|
}
|
||||||
skeletonData = json.readSkeletonDataFile(skeletonFile);
|
binary->setScale(scale);
|
||||||
|
skeletonData = binary->readSkeletonDataFile(skeletonFile);
|
||||||
|
delete binary;
|
||||||
|
} else {
|
||||||
|
SkeletonJson *json = nullptr;
|
||||||
|
if (atlas) {
|
||||||
|
json = new SkeletonJson(atlas);
|
||||||
|
} else {
|
||||||
|
json = new SkeletonJson(&nullLoader);
|
||||||
|
}
|
||||||
|
json->setScale(scale);
|
||||||
|
skeletonData = json->readSkeletonDataFile(skeletonFile);
|
||||||
|
delete json;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationStateData stateData(skeletonData);
|
AnimationStateData stateData(skeletonData);
|
||||||
SkeletonDrawable drawable(skeletonData, &stateData);
|
SkeletonDrawable drawable(skeletonData, &stateData);
|
||||||
drawable.skeleton->setPosition(320, 590);
|
drawable.skeleton->setPosition(320, 590);
|
||||||
drawable.state->setAnimation(0, "walk", true);
|
if (animation.length() > 0) drawable.state->setAnimation(0, animation, true);
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - testbed");
|
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - testbed");
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user