您的位置:首页 > 移动开发 > Cocos引擎

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

2015-11-19 18:33 585 查看
local cache = cc.AnimationCache:getInstance()
cache:addAnimations("animations-2.plist")
local animation = cache:getAnimation("dance_1")
animation:setDelayPerUnit(0.25)
animation:setRestoreOriginalFrame(true)
local aniamte = cc.Animate:create(animation)
sprite:runAction(cc.RepeatForever:create(aniamte))

local listener  = cc.EventListenerCustom:create(cc.ANIMATION_FRAME_DISPLAYED_NOTIFICATION,
function (event, aa,bb,cc )
local name = event:getEventName()
print(name)
end
)

cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(listener, -1);


PS:这是一种非常好的做法,当我们需要做每帧的播放做处理时,就能用到它,userdata获取的接口,没有提供,我们可以自己仿照getEventName那样,
写一个获取getUserData的方法。或者是其他脚本接口函数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: