使用cc.Director:getInstance():setNotificationNode(NotificationNode)来进行实现,并且编写一个简单的延时函数。
global.NotificationNode = cc.Node:create()
global.LoadingPic = cc.Sprite:create("ui/common/LoadingPic.png")
LoadingPic:setAnchorPoint(cc.p(0,0))
LoadingPic:setPosition(cc.p(0,0))
LoadingPic:addChild(Utils.createLoadingNode())
NotificationNode:addChild(LoadingPic)
cc.Director:getInstance():setNotificationNode(NotificationNode)
LoadingNode:setVisible(false)
LoadingPic:setVisible(false)
self.SwallowTouchlistener = Utils.addSwallowTouchListenerToNode(NotificationNode) --屏蔽其他事件。
Utils.ShowTransScenePic()
Utils.delayExcute(0,function()
g_AppInstance:enterScene(CONFIG.REVIEW_VERSION == true and "GameModeScene" or "TeamModeScene")
Utils.HideTransScenePic()
end)
1.将自己做好的loading界面设置到NoNtificationode里面。这样在每次转换的界面的时候就会显示Node。
Utils.ShowTransScenePic()
Utils.delayExcute(0,function()
g_AppInstance:enterScene(CONFIG.REVIEW_VERSION == true and "GameModeScene" or "TeamModeScene")
Utils.HideTransScenePic()
end)
function Utils.delayExcute(delayTm, cb)
local defaultSchedule = cc.Director:getInstance():getScheduler()
local scheduleHandler = nil
local function callback()
if cb ~= nil then
cb()
end
defaultSchedule:unscheduleScriptEntry(scheduleHandler)
table.removebyvalue(delayScheduleHandlers, scheduleHandler)
end
scheduleHandler = defaultSchedule:scheduleScriptFunc(callback, delayTm, false)
delayScheduleHandlers[#delayScheduleHandlers + 1] = scheduleHandler
return scheduleHandler
end
2.Utils.ShowTransScenePic()这个函数是将之前自己设置在directer的notificationNode设置为显示状态。
3.然后自己利用schedule写一个延迟函数,在下一帧的时候进入你想进入的场景。并且影藏notificationNode。(这里为什么要在下一帧,因为Utils.ShowTransScenePic() 里面的setvisible(true) 只是将该图片加入到渲染队列,并不是立即显示在界面上来。而enterScene是会立即跳转界面并且显示,如果不利用延迟函数在下一帧进行enter,那么看到的效果就是进入场景然后显示了notificationNode。 而我们想要的效果是先显示notificationNode界面,scene成功加载在进行跳转。)