嵌套调用:
1.方法A调用方法B
2.B调A
3.A or B里面设置终止条件
--假如有以下文件需要预加载
local PLIST_FILE = {
"res/Image/res_game",
"res/Image/res_ui",
}
function LoadingScene:ctor()
self:updateLoadRes()
end
function LoadingScene:updateLoadRes()
self:runAction(cc.Sequence:create(cc.DelayTime:create(self.per_time),cc.CallFunc:create(function(sender)
display.loadImage(PLIST_FILE[self.loadResNum]..".png", handler(self, self.loadResCallBack))
end)))
end
function LoadingScene:loadResCallBack(texture)
local plistName = PLIST_FILE[self.loadResNum]..".plist"
--加载plist文件
cc.SpriteFrameCache:getInstance():addSpriteFrames(plistName)
local nowPercent = math.min(100, 100*(self.loadResNum/#PLIST_FILE))
self.lod_bar:setPercent(nowPercent) --如果有进度条,更新百分比
if self.loadResNum >= #PLIST_FILE then
print("资源加载完成")
self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function(sender)
local StartScene = require("app/views/StartScene"):create(true)
cc.Director:getInstance():replaceScene(StartScene)
end)))
return
end
self.loadResNum = self.loadResNum + 1
self:updateLoadRes()
end
网友评论