02 使用cocos studio和cocos2d-x LUA , 使用name, ID 取得 sprite

在此展示如何把讀近來的csb的檔案,透過cocos studio 設定的名稱或ID 取得該 sprite ,並且修改該元件,教學影片請看此

完成的程式範例,請再此下載

 

[php]

local MainScene = class("MainScene", cc.load("mvc").ViewBase)

function MainScene:onCreate()
-- add background image
display.newSprite("MainSceneBg.jpg")
:move(display.center)
:addTo(self)

-- add play button
local playButton = cc.MenuItemImage:create("PlayButton.png", "PlayButton.png")
:onClicked(function()
self:getApp():enterScene("PlayScene")
end)
cc.Menu:create(playButton)
:move(display.cx, display.cy - 200)
:addTo(self)

-----------------------------

local function RunExportedCSB(csbFileName)
-- get root node from csb file.
local node = cc.CSLoader:createNode(csbFileName)

-- run animation in the scene
local action = cc.CSLoader:createTimeline(csbFileName)
node:runAction(action)
action:gotoFrameAndPlay(0, true)

-- add csb returned node to scene.
local runningScene = cc.Director:getInstance():getRunningScene()
if runningScene then
self:addChild(node)
end

local btn1=node:getChildByName("Button_Right")
local btn2=node:getChildByTag(430)

local move =cc.MoveBy:create(3, cc.p(200, 0))
local move_back = move:reverse()
local seq1 = cc.Sequence:create(move, move_back)
local a2 = btn2:runAction(cc.RepeatForever:create(seq1))

end
RunExportedCSB("Layer.csb")

end

return MainScene

[/php]

Screen Shot 2015-06-28 at 11.21.50 AM

cococs2d-x LUA
CH02 LUACH04 SceneCH05 SpriteCH09 Cocos2d 原始程式CH10 cocos (cocos studio)CH11 工具CH99範例