瀏覽代碼

Utility methods to read from file and other minor improvements.

NathanSweet 12 年之前
父節點
當前提交
3aab744395

+ 1 - 1
spine-cpp/include/spine/AnimationState.h

@@ -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 */

+ 2 - 0
spine-cpp/include/spine/BaseSkeleton.h

@@ -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 */

+ 2 - 0
spine-cpp/include/spine/BaseSkeletonJson.h

@@ -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;

+ 4 - 0
spine-cpp/src/spine/BaseSkeleton.cpp

@@ -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 */

+ 10 - 0
spine-cpp/src/spine/BaseSkeletonJson.cpp

@@ -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.");

+ 12 - 10
spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java

@@ -39,22 +39,24 @@ public class AnimationState {
 		this.data = data;
 	}
 
+	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 = MathUtils.clamp(mixTime / mixDuration, 0, 1);
+			float alpha = mixTime / mixDuration;
+			if (alpha >= 1) {
+				alpha = 1;
+				previous = null;
+			}
 			current.mix(skeleton, currentTime, currentLoop, alpha);
-			if (alpha == 1) previous = null;
-		} else {
+		} else
 			current.apply(skeleton, currentTime, currentLoop);
-		}
-	}
-
-	public void update (float delta) {
-		currentTime += delta;
-		previousTime += delta;
-		mixTime += delta;
 	}
 
 	/** Set the current animation. */

+ 1 - 1
spine-sfml/.settings/org.eclipse.cdt.codan.core.prefs

@@ -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}}

+ 1 - 1
spine-sfml/include/spine-sfml/Skeleton.h

@@ -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);
 

+ 2 - 0
spine-sfml/include/spine-sfml/spine.h

@@ -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>
 

+ 3 - 7
spine-sfml/src/main.cpp

@@ -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;