溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

在 Lua 里 使用 Cocos Studio 導(dǎo)出的 .csb 文件

發(fā)布時(shí)間:2020-06-16 02:27:58 來源:網(wǎng)絡(luò) 閱讀:3022 作者:e雨 欄目:開發(fā)技術(shù)

1. 加載 節(jié)點(diǎn)到場(chǎng)景

第一種方法

local scene = cc.CSLoader:createNode("scene.csb")
 self:addChild(scene)

第二種方法

local scene = cc.uiloader:load("MainScene.csb"):addTo(self)

2.強(qiáng)轉(zhuǎn)精靈類型

local sprite = tolua.cast(object,"cc.Sprite")

CocoStudio 做的里面的精靈是 CCSprite (c++里面的)類型 不能使用 setPosition 等 一些 Lua 里面的方法  需要 使用 tolua.cast(object,type)進(jìn)行強(qiáng)制轉(zhuǎn)換類型

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. 動(dòng)畫 (播放時(shí)間軸)

local timeline = cc.CSLoader:createTimeline("MainScene.csb");
    scene:runAction(timeline);

    timeline:gotoFrameAndPlay(0,true);

    timeline:setFrameEventCallFunc(function(dt)
         print(dt:getEvent())  -- 幀事件
    end)


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI