在 Lua 里 使用 Cocos Studio 导出的 .csb 文件
1. 加載 節點到場景
第一種方法
local scene = cc.CSLoader:createNode("scene.csb")
?self:addChild(scene)
第二種方法
local scene = cc.uiloader:load("MainScene.csb"):addTo(self)
2.強轉精靈類型
local sprite = tolua.cast(object,"cc.Sprite")
CocoStudio 做的里面的精靈是 CCSprite (c++里面的)類型 不能使用 setPosition 等 一些 Lua 里面的方法? 需要 使用 tolua.cast(object,type)進行強制轉換類型
3.按鈕不一樣的使用方法
local btn = scene:getChildByName("Button_1")
btn:addTouchEventListener(function (event,type)
? if type == ccui.TouchEventType.began then
?? ???? print("began")
??? end??
if type == ccui.TouchEventType.ended then
?? ???? print("ended")
??? end
??? end)
4. 動畫 (播放時間軸)
local timeline = cc.CSLoader:createTimeline("MainScene.csb");
??? scene:runAction(timeline);
??? timeline:gotoFrameAndPlay(0,true);
??? timeline:setFrameEventCallFunc(function(dt)
???????? print(dt:getEvent())? -- 幀事件
??? end)
轉載于:https://blog.51cto.com/10657504/1715210
總結
以上是生活随笔為你收集整理的在 Lua 里 使用 Cocos Studio 导出的 .csb 文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS7 安装 Gitlab
- 下一篇: PHP 发邮件《转》