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

本文介绍了如何使用 Cocos2d-x 的 AnimationCache 进行动画加载和播放,并通过 EventListenerCustom 监听动画帧的显示。这种方法适用于需要对每帧动画进行特定处理的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
 
 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的方法。或者是其他脚本接口函数

转载于:https://www.cnblogs.com/dudu580231/p/4978751.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值