用到quick3.3中的spine(骨骼动画)
在动画某一帧添加event后,在通过
self.skeleteonNode:registerSpineEventHandler(handler(self, function(self,event)
dump(event)
if event.animation == “run” then
if event.name == “footstep” then
print(“footstep”)
end
end
end),sp.EventType.ANIMATION_EVENT)
这个方法得到事件为“footstep”,但是如果方法最后为sp.EventType.ANIMATION_EVENT或sp.EventType.ANIMATION_START或sp.EventType.ANIMATION_END,怎么也进入不到上面的function中,但是sp.EventType.ANIMATION_COMPLETE却可以,我通过断点找到了每一帧都会调用的方法,如下:
void spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) {
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
int i, ii;
int eventsCount;
int entryChanged;
float time;
spTrackEntry* previous;
for (i = 0; i < self->tracksCount; ++i) {
spTrackEntry* current = self->tracks*;
if (!current) continue;
eventsCount = 0;
time = current->time;
if (!current->loop && time > current->endTime) time = current->endTime;
previous = current->previous;
if (!previous) {
if (current->mix == 1) {
spAnimation_apply(current->animation, skeleton, current->lastTime, time,
current->loop, internal->events, &eventsCount);
} else {
spAnimation_mix(current->animation, skeleton, current->lastTime, time,
current->loop, internal->events, &eventsCount, current->mix);
}
} else {
float alpha = current->mixTime / current->mixDuration * current->mix;
float previousTime = previous->time;
if (!previous->loop && previousTime > previous->endTime) previousTime = previous->endTime;
spAnimation_apply(previous->animation, skeleton, previousTime, previousTime, previous->loop, 0, 0);
if (alpha >= 1) {
alpha = 1;
internal->disposeTrackEntry(current->previous);
current->previous = 0;
}
spAnimation_mix(current->animation, skeleton, current->lastTime, time,
current->loop, internal->events, &eventsCount, alpha);
}
entryChanged = 0;
for (ii = 0; ii < eventsCount; ++ii) {
spEvent* event = internal->events;
if (current->listener) {
current->listener(self, i, SP_ANIMATION_EVENT, event, 0);
if (self->tracks* != current) {
entryChanged = 1;
break;
}
}
if (self->listener) {
self->listener(self, i, SP_ANIMATION_EVENT, event, 0);
if (self->tracks* != current) {
entryChanged = 1;
break;
}
}
}
if (entryChanged) continue;
/* Check if completed the animation or a loop iteration. */
if (current->loop ? (FMOD(current->lastTime, current->endTime) > FMOD(time, current->endTime))
: (current->lastTime < current->endTime && time >= current->endTime)) {
int count = (int)(time / current->endTime);
if (current->listener) {
current->listener(self, i, SP_ANIMATION_COMPLETE, 0, count);
if (self->tracks* != current) continue;
}
if (self->listener) {
self->listener(self, i, SP_ANIMATION_COMPLETE, 0, count);
if (self->tracks* != current) continue;
}
}
current->lastTime = current->time;
}
}
这个方法中有个参数int eventsCount; 这个eventsCount被赋值为0,下面又有个循环for (ii = 0; ii < eventsCount; ++ii),但是这个局部变量的值并没有发生改变,所以怎么也执行不到for循环中的方法,也就找不到骨骼动画的帧事件了。本人新人一枚,看源码也是马马虎虎,希望有了解的前辈指教。如果是我的方法用错了,能直接告诉我正确的使用方法是最好了,谢谢大家了!*****