(转)cocos2d-x 每帧动画的播放设置一个监听函数的做法

 
 
 1  local cache = cc.AnimationCache:getInstance()
 2     cache:addAnimations("animations-2.plist")
 3     local animation = cache:getAnimation("dance_1")
 4     animation:setDelayPerUnit(0.25)
 5     animation:setRestoreOriginalFrame(true)
 6     local aniamte = cc.Animate:create(animation)
 7     sprite:runAction(cc.RepeatForever:create(aniamte))
 8 
 9      local listener  = cc.EventListenerCustom:create(cc.ANIMATION_FRAME_DISPLAYED_NOTIFICATION,
10                      function (event, aa,bb,cc )
11                         local name = event:getEventName()
12                            print(name)
13                      end
14         )
15      
16     cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(listener, -1);
17    

 


PS:这是一种非常好的做法,当我们需要做每帧的播放做处理时,就能用到它,userdata获取的接口,没有提供,我们可以自己仿照getEventName那样, 写一个获取getUserData的方法。或者是其他脚本接口函数

posted @ 2015-11-19 18:33  silent-bobo  阅读(289)  评论(0编辑  收藏  举报