quick-lua 获取Cocos Studios动画播放回调
来源:互联网 发布:淘宝卖童装货源 编辑:程序博客网 时间:2024/06/13 13:09
quick-lua 版本是3.5
cocos studios是2.0以上,目前是最新版本
在cocos studios中回调使用帧事件也是可以的,就是在关键帧上设置回调事件:
设置的时候,要选中开始记录动画,然后选中关键帧,再设置事件名称。在动画执行到这一帧时会触发该事件,在lua中使用方式为:
local eventFrameCall = function(frame) local eventName = frame:getEvent() if eventName == "wait" then end end end timeline:clearFrameEventCallFunc() timeline:setFrameEventCallFunc(eventFrameCall) timeline:play("wait", false)
但这种方式很繁琐,在修改动画的时候很容易忘记有这个事件而出错
在使用cocosbuilder的时候,可以设置动画回调函数。在cocos studios也有这个的回调,但在quick-lua 3.5中还没有支持。所以下面记录另外一种回调方式。
简单说就是获取动画执行时间,手动设置回调方法:
timeline:play("wait", false) local duration = UIHelper.getAnimationDuration(timeline local block = cc.CallFunc:create( function(sender) callBack() end ) self:runAction(cc.Sequence:create(cc.DelayTime:create(duration), block))
通过UIHelper.getAnimationDuration方法获取动画执行的时间:
function UIHelper.getAnimationDuration(timeline) local speed = timeline:getTimeSpeed()-- local duration = timeline:getDuration() local startFrame = timeline:getStartFrame() local endFrame = timeline:getEndFrame() local frameNum = endFrame - startFrame return 1.0 /(speed * 60.0) * frameNumend
这样的方法虽然增加一些代码,但减少因编辑器经常更新而造成的问题
完整的UIHelper.lua如下:
UIHelper = {}-- tolua.cast(ccsLayout:getChildByName("server_list") ,"ListView") .function UIHelper.getControl(root,parentNames) local newRoot = root for i = 1,#parentNames do local name = parentNames[i] local child = newRoot:getChildByName(name) if not child then newRoot = nil break else newRoot = child end end return newRootendfunction UIHelper.createNode(parent,file,pos) local layout = cc.CSLoader:createNode(file) if pos then layout:setPosition(pos) end parent:addChild(layout) local timeline = cc.CSLoader:createTimeline(file) layout:runAction(timeline) return layout,timelineendfunction UIHelper.getAnimationDuration(timeline) local speed = timeline:getTimeSpeed()-- local duration = timeline:getDuration() local startFrame = timeline:getStartFrame() local endFrame = timeline:getEndFrame() local frameNum = endFrame - startFrame return 1.0 /(speed * 60.0) * frameNumendfunction UIHelper.runTimeline(layout,timeline, animationName,loop) if not loop then loop = false end if animationName ~= nil and timeline:IsAnimationInfoExists(animationName) then timeline:play(animationName, loop) else timeline:gotoFrameAndPlay(0, loop) endend--function UIHelper.runTimelineAndClear(layout,timeline, animationName) UIHelper.runAction(layout,timeline, animationName) local duration = UIHelper.getAnimationDuration(timeline) local block = cc.CallFunc:create( function(sender) layout:removeSelf() end ) layout:runAction(cc.Sequence:create(cc.DelayTime:create(duration), block))endfunction UIHelper.runTimelineAndCall(layout,timeline, animationName,callBack) local duration = UIHelper.getAnimationDuration(timeline) local block = cc.CallFunc:create( function(sender) return callBack end ) layout:runAction(cc.Sequence:create(cc.DelayTime:create(duration), block))end
QQ群:239759131 cocos 技术交流 欢迎您
0 0
- quick-lua 获取Cocos Studios动画播放回调
- lua cocos 动画回调
- cocos-quick-lua 学习笔记--定时器:scheduler
- quick-cocos 3.5 lua banding c++
- cocos-lua 场景切换动画
- cocos-lua帧动画使用
- cocos-Lua添加骨骼动画
- quick-lua创建骨骼动画
- cocos2d-Lua(quick-cocos)开发环境搭建
- cocos-quick-lua学习笔记---遍历table(in pairs)
- cocos-lua学习笔记(八)帧动画
- 【Cocos-Quick】quick源文件中关于lua的import和require的区别
- cocos 获取所有子节点 -lua
- 【quick-lua 001】 lua的过渡动画类型
- Cocos2d-x Lua 使用Cocos Studio导出的动画
- Cocos2d-x lua 使用Cocos Studio导出的动画
- Cocos2d-x lua 使用Cocos Studio导出的动画
- cocos lua csb动画返回到开始处
- Android生命周期与Java类周期的交互融合
- NSCopying
- sublime自己写build System
- 排序相关代码
- Android中Cursor类的概念和用法
- quick-lua 获取Cocos Studios动画播放回调
- 安卓面试题精华
- Jetty实战之 安装 运行 部署
- java SE复习笔记15
- USACO Section 1.5
- 信息存储与IT管理——互动出版网
- 黑马程序员——Java之多线程(1)
- 圆角边框
- jfinal图片上传