From ef5f68d8fa646994f7a77de536c30d455f597456 Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 4 Dec 2018 16:34:20 +0100 Subject: [PATCH] [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. --- spine-cocos2dx/src/spine/SkeletonAnimation.cpp | 10 ++++++++++ spine-cocos2dx/src/spine/SkeletonAnimation.h | 1 + 2 files changed, 11 insertions(+) diff --git a/spine-cocos2dx/src/spine/SkeletonAnimation.cpp b/spine-cocos2dx/src/spine/SkeletonAnimation.cpp index c3947d72b..d18290fd6 100644 --- a/spine-cocos2dx/src/spine/SkeletonAnimation.cpp +++ b/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."); diff --git a/spine-cocos2dx/src/spine/SkeletonAnimation.h b/spine-cocos2dx/src/spine/SkeletonAnimation.h index d6521d63d..45e0ca3bf 100644 --- a/spine-cocos2dx/src/spine/SkeletonAnimation.h +++ b/spine-cocos2dx/src/spine/SkeletonAnimation.h @@ -109,6 +109,7 @@ protected: spAnimationState* _state; bool _ownsAnimationStateData; + bool _firstDraw; StartListener _startListener; InterruptListener _interruptListener;