local BaseLayer = class("BaseLayer", function()
return display.newLayer()
end)
function BaseLayer:ctor(...)
self:setNodeEventEnabled(true)
self:setTouchSwallowEnabled(false)
end
function BaseLayer:onEnter()
end
function BaseLayer:onExit()
end
function BaseLayer:onEnterBackground()
end
function BaseLayer:onEnterForeground()
end
return BaseLayer
继承的BaseUI
local LoadingView = class("LoadingView",BaseUI)
--需要加载的plist文件
local PLIST_FILE = {
"unit/base/unit23_dead" ,
"unit/blue/blue_unit23_dead" ,
"unit/green/green_unit23_dead" ,
"unit/yellow/yellow_unit23_dead" ,
"ani/unit1/unit1" ,
"ani/unit_17/unit17" ,
"ani/unit_17/unit_17_flash" ,
"ani/attack/ATK_1" ,
"ani/attack/ATK_2" ,
"ani/attack/SPECIAL_1" ,
"unit/base/unit1",
"unit/base/unit2",
"unit/base/unit3",
"unit/base/unit4",
"unit/base/unit5",
"unit/base/unit6",
"unit/base/unit7",
"unit/base/unit8",
"unit/base/unit9",
"unit/base/unit10",
"unit/base/unit11",
"unit/base/unit12",
"unit/base/unit13",
"unit/base/unit14",
"unit/base/unit15",
"unit/base/unit16",
"unit/base/unit17",
"unit/base/unit18",
"unit/base/unit19",
"unit/base/unit20",
"unit/base/unit21",
"unit/base/unit22",
"unit/base/unit23",
}
function LoadingView:ctor()
-- LoadingView.super.ctor(self, 0, false,true)
local bg = display.newSprite("UI/login_bg.png")
bg:setAnchorPoint(cc.p(0, 0))
self:addChild(bg)
self.loadResNum = 0
local loadingBg = cc.Sprite:createWithSpriteFrameName("loadgame_bg.png")
loadingBg:setPosition(cc.p(display.cx, display.height / 10))
self:addChild(loadingBg)
local loading = cc.Sprite:createWithSpriteFrameName("loadgame_inner.png")--display.newSprite(loadStr)
self.loadingBar = display.newProgressTimer(loading, cc.PROGRESS_TIMER_TYPE_BAR):addTo(self)
self.loadingBar:setMidpoint(cc.p(0, 0))
self.loadingBar:setBarChangeRate(cc.p(1, 0))
self.loadingBar:setPercentage(0)
self.loadingBar:setPosition(cc.p(0, 0))
self.loadingBar:setPosition(cc.p(display.cx, display.height / 10))
self:updateLoadRes()
end
function LoadingView:updateLoadRes()
local updateTimes = 0
local nowLoadNums = 0
local function updateLoad(dt)
updateTimes = updateTimes + 1
if updateTimes > 20 and updateTimes % 3 == 0 then
nowLoadNums = nowLoadNums + 1
display.addSpriteFrames(PLIST_FILE[nowLoadNums]..".plist", PLIST_FILE[nowLoadNums]..".png", handler(self,self.loadResCallBack))
end
if #PLIST_FILE <= nowLoadNums then
cc.vv.dump(" -- > stop update load res ... ")
self:closeSchedule()
--关闭加载层
cc.vv.layerMgr:removeLayer("LoadingView")
end
end
self.scheduleListener = cc.Director:getInstance():getScheduler():scheduleScriptFunc(updateLoad , 0 , false)
end
function LoadingView:closeSchedule()
print("关闭调度器-1")
if self.scheduleListener ~= nil then
print("关闭调度器-2")
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.scheduleListener)
self.scheduleListener = nil
end
end
function LoadingView:loadResCallBack(texture2d)
self.loadResNum = self.loadResNum + 1
cc.vv.dump(self.loadResNum,"loadResNum")
local nowPercent = math.min( 100,100*(self.loadResNum/#PLIST_FILE))
self.loadingBar:setPercentage(nowPercent)
dump(nowPercent, "nowPercent", 10)
if nowPercent >= 100 then
--资源加载完成
cc.vv.dump("资源加载完成----")
end
end
return LoadingView