mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-19 00:06:42 +08:00
Utility methods to read from file and other minor improvements.
This commit is contained in:
parent
6899b5249c
commit
3aab744395
@ -53,7 +53,7 @@ public:
|
||||
void apply (BaseSkeleton *skeleton);
|
||||
|
||||
void setAnimation (Animation *newAnimation, bool loop, float time);
|
||||
void setAnimation (Animation *animation, bool loop);
|
||||
void setAnimation (Animation *animation, bool loop = false);
|
||||
};
|
||||
|
||||
} /* namespace spine */
|
||||
|
||||
@ -72,6 +72,8 @@ public:
|
||||
Attachment* getAttachment (const std::string &slotName, const std::string &attachmentName) const;
|
||||
Attachment* getAttachment (int slotIndex, const std::string &attachmentName) const;
|
||||
void setAttachment (const std::string &slotName, const std::string &attachmentName);
|
||||
|
||||
void update (float deltaTime);
|
||||
};
|
||||
|
||||
} /* namespace spine */
|
||||
|
||||
@ -44,11 +44,13 @@ public:
|
||||
BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
||||
virtual ~BaseSkeletonJson ();
|
||||
|
||||
SkeletonData* readSkeletonDataFile (const std::string &path) const;
|
||||
SkeletonData* readSkeletonData (std::ifstream &file) const;
|
||||
SkeletonData* readSkeletonData (std::istream &file) const;
|
||||
SkeletonData* readSkeletonData (const std::string &json) const;
|
||||
SkeletonData* readSkeletonData (const char *begin, const char *end) const;
|
||||
|
||||
Animation* readAnimationFile (const std::string &path, const SkeletonData *skeletonData) const;
|
||||
Animation* readAnimation (std::ifstream &file, const SkeletonData *skeletonData) const;
|
||||
Animation* readAnimation (std::istream &file, const SkeletonData *skeletonData) const;
|
||||
Animation* readAnimation (const std::string &json, const SkeletonData *skeletonData) const;
|
||||
|
||||
@ -176,4 +176,8 @@ void BaseSkeleton::setAttachment (const string &slotName, const string &attachme
|
||||
throw invalid_argument("Slot not found: " + slotName);
|
||||
}
|
||||
|
||||
void BaseSkeleton::update (float deltaTime) {
|
||||
time += deltaTime;
|
||||
}
|
||||
|
||||
} /* namespace spine */
|
||||
|
||||
@ -65,6 +65,11 @@ BaseSkeletonJson::~BaseSkeletonJson () {
|
||||
delete attachmentLoader;
|
||||
}
|
||||
|
||||
SkeletonData* BaseSkeletonJson::readSkeletonDataFile (const string &path) const {
|
||||
std::ifstream file(path.c_str());
|
||||
return readSkeletonData(file);
|
||||
}
|
||||
|
||||
SkeletonData* BaseSkeletonJson::readSkeletonData (std::ifstream &file) const {
|
||||
if (!file) throw invalid_argument("file cannot be null.");
|
||||
if (!file.is_open()) throw runtime_error("Skeleton file is not open.");
|
||||
@ -204,6 +209,11 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
return skeletonData;
|
||||
}
|
||||
|
||||
Animation* BaseSkeletonJson::readAnimationFile (const string &path, const SkeletonData *skeletonData) const {
|
||||
std::ifstream file(path.c_str());
|
||||
return readAnimation(file, skeletonData);
|
||||
}
|
||||
|
||||
Animation* BaseSkeletonJson::readAnimation (std::ifstream &file, const SkeletonData *skeletonData) const {
|
||||
if (!file) throw invalid_argument("file cannot be null.");
|
||||
if (!file.is_open()) throw runtime_error("Animation file is not open.");
|
||||
|
||||
@ -39,24 +39,26 @@ public class AnimationState {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton) {
|
||||
if (current == null) return;
|
||||
if (previous != null) {
|
||||
previous.apply(skeleton, previousTime, previousLoop);
|
||||
float alpha = MathUtils.clamp(mixTime / mixDuration, 0, 1);
|
||||
current.mix(skeleton, currentTime, currentLoop, alpha);
|
||||
if (alpha == 1) previous = null;
|
||||
} else {
|
||||
current.apply(skeleton, currentTime, currentLoop);
|
||||
}
|
||||
}
|
||||
|
||||
public void update (float delta) {
|
||||
currentTime += delta;
|
||||
previousTime += delta;
|
||||
mixTime += delta;
|
||||
}
|
||||
|
||||
public void apply (Skeleton skeleton) {
|
||||
if (current == null) return;
|
||||
if (previous != null) {
|
||||
previous.apply(skeleton, previousTime, previousLoop);
|
||||
float alpha = mixTime / mixDuration;
|
||||
if (alpha >= 1) {
|
||||
alpha = 1;
|
||||
previous = null;
|
||||
}
|
||||
current.mix(skeleton, currentTime, currentLoop, alpha);
|
||||
} else
|
||||
current.apply(skeleton, currentTime, currentLoop);
|
||||
}
|
||||
|
||||
/** Set the current animation. */
|
||||
public void setAnimation (Animation animation, boolean loop) {
|
||||
setAnimation(animation, loop, 0);
|
||||
|
||||
@ -19,7 +19,7 @@ org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning
|
||||
org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()}
|
||||
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error
|
||||
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
|
||||
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=-Warning
|
||||
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning
|
||||
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true}
|
||||
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error
|
||||
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
|
||||
|
||||
@ -34,7 +34,7 @@ namespace spine {
|
||||
class Skeleton: public BaseSkeleton, public sf::Drawable {
|
||||
public:
|
||||
sf::VertexArray vertexArray;
|
||||
sf::Texture *texture; // This is a bit ugly and means all region attachments must use the same textures.
|
||||
sf::Texture *texture; // All region attachments must use the same texture.
|
||||
|
||||
Skeleton (SkeletonData *skeletonData);
|
||||
|
||||
|
||||
@ -32,6 +32,8 @@
|
||||
#include <spine/Skin.h>
|
||||
#include <spine/Attachment.h>
|
||||
#include <spine/Animation.h>
|
||||
#include <spine/AnimationStateData.h>
|
||||
#include <spine/AnimationState.h>
|
||||
#include <spine/Slot.h>
|
||||
#include <spine/Bone.h>
|
||||
|
||||
|
||||
@ -37,13 +37,9 @@ int main () {
|
||||
ifstream atlasFile("../data/spineboy.atlas");
|
||||
Atlas *atlas = new Atlas(atlasFile);
|
||||
|
||||
SkeletonJson skeletonJson(atlas);
|
||||
|
||||
ifstream skeletonFile("../data/spineboy-skeleton.json");
|
||||
SkeletonData *skeletonData = skeletonJson.readSkeletonData(skeletonFile);
|
||||
|
||||
ifstream animationFile("../data/spineboy-walk.json");
|
||||
Animation *animation = skeletonJson.readAnimation(animationFile, skeletonData);
|
||||
SkeletonJson json(atlas);
|
||||
SkeletonData *skeletonData = json.readSkeletonDataFile("../data/spineboy-skeleton.json");
|
||||
Animation *animation = json.readAnimationFile("../data/spineboy-walk.json", skeletonData);
|
||||
|
||||
Skeleton *skeleton = new Skeleton(skeletonData);
|
||||
skeleton->flipX = false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user