Browse Source

[cocos2dx] Closes #1216. Cocos2dx may draw a SkeletonAnimation node before its update method is called. The skeleton is thus rendered in the setup pose for the first frame.

badlogic 6 years ago
parent
commit
ef5f68d8fa

+ 10 - 0
spine-cocos2dx/src/spine/SkeletonAnimation.cpp

@@ -116,6 +116,8 @@ void SkeletonAnimation::initialize () {
 	_state->listener = animationCallback;
 
 	_spAnimationState* stateInternal = (_spAnimationState*)_state;
+	
+	_firstDraw = true;
 }
 
 SkeletonAnimation::SkeletonAnimation ()
@@ -136,6 +138,14 @@ void SkeletonAnimation::update (float deltaTime) {
 	spSkeleton_updateWorldTransform(_skeleton);
 }
 
+void SkeletonAnimation::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t transformFlags) {
+	if (_firstDraw) {
+		_firstDraw = false;
+		update(0);
+	}
+	super::draw(renderer, transform, transformFlags);
+}
+
 void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) {
 	CCASSERT(stateData, "stateData cannot be null.");
 

+ 1 - 0
spine-cocos2dx/src/spine/SkeletonAnimation.h

@@ -109,6 +109,7 @@ protected:
 	spAnimationState* _state;
 
 	bool _ownsAnimationStateData;
+	bool _firstDraw;
 
 	StartListener _startListener;
     InterruptListener _interruptListener;