如果当前没有动画,用
local HeroHand = cc.CSLoader:createNode( “Hero.csb” );
创建出动画,再给它加上ActionTimeline。
local HeroTimeline = cc.CSLoader:createTimeline( “Hero.csb” );
调用 runAction 函数
HeroHand:runAction( HeroTimeline);
将创建出来的 Hand 添加到显示层级
Layer:addChild( HeroHand);
可以给动画设置帧事件的回调
HeroTimeline:setFrameEventCallFunc( function( event )
local eventName = event:getEvent();
--eventName 得到的就是在编辑器里设置的帧事件字符串
print( "eventName = " .. tostring( eventName) );
end);
在lua里面没法设置结束回调。。。但是你可以在结束的那一帧设置一个帧事件 字符串 你随便,用上面的函数判断下你设置的最后一帧的字符串,就知道是不是最后一帧了。
调用播放动画也很简单:
C++里面有很多的播放函数
/** Goto the specified frame index,and start playing from this index. * @param startIndex The animation will play from this index. */ virtual void gotoFrameAndPlay(int startIndex); /** Goto the specified frame index,and start playing from this index. * @param startIndex The animation will play from this index. * @param loop Whether or not the animation need loop. */ virtual void gotoFrameAndPlay(int startIndex,bool loop); /** Goto the specified frame index,and start playing from start index,end at end index. * @param startIndex The animation will play from this index. * @param endIndex The animation will end at this index. * @param loop Whether or not the animation need loop. */ virtual void gotoFrameAndPlay(int startIndex,int endIndex,end at end index. * @param startIndex The animation will play from this index. * @param endIndex The animation will end at this index. * @param currentFrameIndex set current frame index. * @param loop Whether or not the animation need loop. */ virtual void gotoFrameAndPlay(int startIndex,int currentFrameIndex,bool loop);
上面的都是通过帧播放,
virtual void play(std::string animationName,bool loop);
这个函数是通过名字播放 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|