找尋和移除Sprite

[php]

function GameScene:loading()

local layer = cc.Layer:create()

layer:setName("loadinglayer")

local bg = cc.Sprite:create("bg2.jpg")
bg:setPosition( self.visibleSize.width / 2 , self.visibleSize.height / 2)
bg:setScale(self.visibleSize.width/183,self.visibleSize.height/257)
layer:addChild(bg)

local loading = cc.Sprite:create("loading.png")
loading:setPosition( self.visibleSize.width / 2 , self.visibleSize.height / 2+50)
-- loading:setScale(self.visibleSize.width/183,self.visibleSize.height/257)
layer:addChild(loading)

loading:setName("loading")
loading:runAction(cc.RepeatForever:create(cc.RotateBy:create(2, 90)))

return layer
end

function GameScene:removeLoading(iScene)
local layerLoading=iScene:getChildByName("loadinglayer")
local layerbyName = layerLoading:getChildByName("loading")
layerbyName:removeFromParent()
end
[/php]

使用方法
[php]
local function main()
collectgarbage("collect")
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)
local director = cc.Director:getInstance()
director:setAnimationInterval(1.0 / 60)
cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 0)
local scene = require("GameScene")
local gameScene = scene.create()
if cc.Director:getInstance():getRunningScene() then
cc.Director:getInstance():replaceScene(gameScene)
gameScene:readimages(gameScene)
gameScene:removeLoading(gameScene)
end
end
[/php]

範例程式在
Tutorial_Sprite_getChildByName_remoFromParent

Screen Shot 2015-07-04 at 10.09.53 AM

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