我用cocostudio创建了一个骨骼动画,里面包含attack和idle两个动画,并且我给attack的第一帧设置了一个帧事件a1。同时我设置setFrameEventCallFunc去播放一个我做好的帧动画,里面的动画叫"effect"。这个帧动画希望能跟着挂接骨骼一起走,这个挂接骨骼叫PHnode1。代码用lua写的
local effect = cs.Armature:create("invincible")
local bone = armature:getAnimation():getBone("PHnode1")
if bone then
bone:addDisplay(effect, 0)
bone:changeDisplayWithIndex(0, true)
bone:setIgnoreMovementBoneData(true)
end
armature:getAnimation():play("attack", -1 , 0)
local function frameEvent(bone,evt,originFrameIndex,currentFrameIndex)
print("frameEvent-------")
effect:getAnimation():play("effect", -1, 0)
end
armature:getAnimation():setFrameEventCallFunc(frameEvent)
local count = 0
function switchAnimation( armature, movementType, movementId )
if ccs.MovementEventType.complete == movementType then
if count == 1 then
armature:getAnimation():play("idle", -1 , 0)
else
armature:getAnimation():play("attack", -1 , 0)
end
count = 1 - count
end
end
armature:getAnimation():setMovementEventCallFunc(switchAnimation)
然后这段代码应该会反复的播放attack,idle两个动画,并且在attack的时候去触发帧事件播放effect动画。
实际上在播放effect动画会不停的飞出去。如果没有动画切换,只是播放attack动画,这个时候effect动画就能正确工作,跟着HPnode走,每次帧事件播放一次,也不飞出去。
希望有高手能帮我解答一下,非常感谢!