[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.

This commit is contained in:
badlogic 2018-12-04 16:34:20 +01:00
parent fd26abdd88
commit ef5f68d8fa
2 changed files with 11 additions and 0 deletions

View File

@ -116,6 +116,8 @@ void SkeletonAnimation::initialize () {
_state->listener = animationCallback; _state->listener = animationCallback;
_spAnimationState* stateInternal = (_spAnimationState*)_state; _spAnimationState* stateInternal = (_spAnimationState*)_state;
_firstDraw = true;
} }
SkeletonAnimation::SkeletonAnimation () SkeletonAnimation::SkeletonAnimation ()
@ -136,6 +138,14 @@ void SkeletonAnimation::update (float deltaTime) {
spSkeleton_updateWorldTransform(_skeleton); 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) { void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) {
CCASSERT(stateData, "stateData cannot be null."); CCASSERT(stateData, "stateData cannot be null.");

View File

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