最近研究到骨骼动画了,发现了很多的问题。比如对于新编cocos stduio2.3.3导出骨骼动画来讲,最终加载出的骨骼动画是ActionTimeline类型的。
ActionTimeline有一个方法:setAnimationEndCallFunc(),注册后在动画每一次播放完毕后,会回调指定的callback方法。
但经实测,此回调方法并不是每一次都执行的!
关键代码如下:
FileUtils::getInstance()->addSearchPath(“bone_animations”);
cocostudio::timeline::SkeletonNode* skeleton = (cocostudio::timeline::SkeletonNode*)CSLoader::createNode(“bone_animations/Skeleton.csb”);
skeleton->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
skeleton->setTag(1);
//加载资源文件中的骨骼动画
timeline::ActionTimeline *at = CSLoader::createTimeline(“bone_animations/Skeleton.csb”);
at->play(“animation0”, true);//找到名为“animation0”的动画,设置为循环
//对cocos studio中已经记录的帧事件,会引起以下回调
at->setFrameEventCallFunc(CC_CALLBACK_1(HelloWorld::onFrame, this));
at->setAnimationEndCallFunc(“animation0”, CC_CALLBACK_0(HelloWorld::onPlayEnd, this));
skeleton->runAction(at);//骨骼对象运行骨骼动画
回调方法:
void HelloWorld::onFrame(cocostudio::timeline::Frame * frame)
{
琀椀洀攀氀椀渀攀::EventFrame * eventFrame = (timeline::EventFrame *)frame;
//获得当前事件帧的事件名
猀琀搀::string strEvent = eventFrame->getEvent();
椀昀 (strEvent == “cut_begin”)//如果当前事件为开始劈下
笀
氀漀最(“cut_begin”);//刀开始劈下时输出"cut_begin"
紀
}
void HelloWorld::onPlayEnd()
{
氀漀最(“cut_end”);//动画播放结束后会输出"cut_end"
}
但经过调试输出结果发现,动画结束回调并不会每一次都执行:
cut_begin
cut_end
cut_begin//连续2次没有执行动画结束回调方法
cut_begin//连续2次没有执行动画结束回调方法
cut_begin
cut_end
cut_begin
cut_end
cut_begin
cut_end
cut_begin//此处没有执行动画结束回调方法
cut_begin
cut_end
cut_begin//此处没有执行动画结束回调方法
cut_begin
cut_end
请问怎么解决啊。。。
另外,我把setAnimationEndCallFunc这种,换成了骨骼动画最后一帧添加帧事件的回调,一样是上面的结果,不会每次都执行。。。