CocoStudio Lua(lua)动画调用 导出的基本动画播放

如果当前没有动画,用

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, 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 currentFrameIndex set current frame index. 
     * @param loop Whether or not the animation need loop. 
     */
    virtual void gotoFrameAndPlay(int startIndex, int endIndex, int currentFrameIndex, bool loop);

上面的都是通过帧播放,

virtual void play(std::string animationName, bool loop);

这个函数是通过名字播放



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值