How to add overlay scene before calling logic.replace

Hi there,

I would like to know how I can add an overlay (loading screen) before calling logic.replace to switch the scene.

Desired order of events:
request from player to load map
add load overlay screen
replace scene
load map
remove load scene

Despite the fact that I’m calling scene.addScene before doing logic.replace, the overlay is not being added until the scene has loaded. So when I click on a button, the menu screen freezes, the load screen will then show when the new scene has loaded and the load screen finishes at the end of my loading script as desired.

So, everything else is working as desired, I just can’t get the overlay scene to show before doing doing all the loading.

from bge import logicimport Rasterizer
scene = logic.getCurrentScene()
cont = logic.getCurrentController()


def LoadMap(LevelToLoad):
    logic.globalDict['LevelToLoad'] = LevelToLoad
    logic.saveGlobalDict()
    Rasterizer.showMouse(False)    
    scene.replace('LevelPlaceHolder')    


L_Click = cont.sensors['L_Click']
mouseOver = cont.sensors['mouseOver']
hitObject = mouseOver.hitObject


if L_Click.positive and mouseOver.positive:
    
    if hitObject.name == "Button_Level_OverGrowth":
        logic.addScene('Overlay_LevelLoading')
        LoadMap('Level_OverGrowth')
        
    if hitObject.name == "Button_Level_MaglevControl":
        
        logic.addScene('Overlay_LevelLoading')
        LoadMap('Level_MaglevControl')
        
    if hitObject.name == "Button_Exit":
        cont.activate(cont.actuators['ExitGame'])

Hello! Could you provide a .blend, please?

Never mind, I went for a slightly different solution in the end.
I replaced the scene completely to the load screen, and then replaced that scene witht the level scene.

Isn’t making a “loading scene” a bad idea? Making an overlay scene wont do much of anything for you since the GE stops all internal processes until the next datablock has been successfully loaded. You’d be better off just spawning a picture over your viewport that says “loading”. That way you won’t be using up resources that could be dedicated to loading the next datablock quicker. :slight_smile:

Hey Terra,

Thanks for that. It hadn’t even crossed my mind to use something so simple! :slight_smile: I’ll look in to that :slight_smile: