Bge Loading screen

i’m working for a game .but when i start game engine in my menù, I have to wait about 15 sec before the game begins. someone can tell me athe script for a loading scene that load all the scene afther the menu or a .blend exaple?:frowning:

as the videogame


I’m afraid loading scripts are highly specialized depending on your exact game setup.
Here’s the basic outline of one:

  1. Use the set scene actuator to switch to a scene with only a single empty in it (loads really fast)
  2. On the first frame of this scene, a script decides what blend you want to load (yes, it must be a seperate blend) and executes the command:
handle = bge.logic.LibLoad(blendname, 'scene', async=True)
  1. Every frame, a script runs:
percent_done = handle.progress
  1. Every frame, the same script uses it to modify a loading bar (I suggest the BGUI module)
  2. When percent_done == 1, stop displaying the loading bar, as the game is loaded.

I’m using replace to change from scenes, then if I want to add progress bar I need to have two blends?

Example: Blend1 with scenes main menu and load scene, in main menu go to load scene with replace and there I use libload to blend2 how sdfgeoff said? it’s ok?

I"m afraid you can’t have a loading bar using different scenes in the same blend.
Yup, that process sounds OK.

One of these days I’ll make a demo for dynamic loading scenes. If I get time today, I’ll do it.

It’d be a nice feature to look into to do asynchronous loading, but for scenes in the same blend file. Perhaps it could best to expand LibLoad() to take “None” as the data argument to specify the “current” blend file. Then, it would load the scene up, and when complete, you can switch scenes immediately. That’s an idea, anyway.

http://www.blender.org/documentation/blender_python_api_2_69_1/bge.types.KX_LibLoadStatus.html#bge.types.KX_LibLoadStatus

I hope explain correctly. First I have 2 blend: load.blend and game.blend both with an empty

load.blend has an empty that



handle = bge.logic.libload("game.blend", "Scene", async=True) # I don't sure if I can execute on finish a function with multiple parameters. Maybe .onFinish and remove the empty or the scene when game is loaded?

print(handle.progress) # example



class Character():
    def __init__(self, name):
        self.nombre = nombre
        path = bge.logic.expandPath("//characters/" + name + ".blend")

        if(path not in bge.logic.LibList()):
            bge.logic.LibLoad(ruta, "Scene",load_actions=True, async=True)



    def spawn(self):
        self.object = bge.logic.getCurrentScene().addObject(....) #No relevant


    def anotherFunction(self):
        pass

Then this code not work with libload async=True fail, I believe that I need use .onFinish with libload on Character.init
With async=False in Character works, but progress bar is frozen because don’t advance frame until libload end then I need async=False for progress bar be dinamic.


class Game():
    def __init__(self):
        self.player = Character("soldier")
       
        self.player.spawn() # this fail
        self.player.anotherFunction # and this

    self.enemy = Character("enemy")
    self.enemy.spawn()


Anyone can help me? Maybe adding .onFinish in libload on Charater.init() and it executing something?

I’ve also noticed that something seems to be wrong with handle.progress.

I did have time yesterday to make a dynamic loading screen example, and it’s sitting on my hard drive, but the loading bar goes from 0 to 100 precent in a single frame, even though it’s percentage is determined by the handle.progress.
Printing out the handle.progress reveals that there are no numbers between them.

I’ll continue to do some investigation before I upload the demo.

Maybe using @async callback? I don’t know really

I’m already using the async callback to close the loading screen, but the handle.progress refuses to update itself.
I should add that the script that does the loading is ‘load.py’ in the scripts folder.

Here’s the blend in a zip. This is not quite complete, so I’ll update it later.
dynamic loading example.zip (1.57 MB)

The main thing that isn’t done is the progression from one level to the next. Current it will only load the first level.

Could it be that the progression is determined by how many individual objects have been loaded instead of faces loaded?

Thanks for blend. Maybe fail is update global variable. I’m researching this

I try globals().update(status) in load.update function but show this error
TypeError: ‘KX_LibLoadStatus’ object is not iterable

@Linkxgl
Doesn’t seem to be. I added a couple of other high-poly objects and it made no difference.
However, it may update on things like models, textures, lighting etc. Of which my scene does not fill.
Time to do some testing…

– edit –
Adding greater variety of models and textures appears to make no differences at all.
– end of edit –

@p9ablo
I doubt it’s a problem with global variables not being updated, because the handle ‘status’ is a handle. It does not contain any information, but instead points at the object created by the libload command. Thus the thing it’s pointing at is updated, but the thing pointing it at it doesn’t have to be.

And the fact is that no matter how you arrange it, you will always need some sort of global variable to store the handle.

I went and opened up a file where I had used dynamic libloading in the past, and was disappointing to find that it’s progress bar had also stopped working. I wonder if a recent update has exposed a bug in blender?

The loading percentage works for me if i use my own blend, if i use the example it wont work (my blend is just 1.2mb) so thats a bit strange. Using 2.69 btw, only thing is, if i use my own level in it. the hud lights wont work well. The other scenes gets also drawn on the floor ingame. but thats probally becouse of just placing my blend as level1.

I would say great work, always tried to figure out how it should work.

What Blender 2.69 bits version, and what SO are you using?

blender 2.69.0 r60995, 64 bit version, uhm no idea what SO means.

oh you mean os? windows 8.1

Yes it was os :wink:
Thanks maybe be that, I’m using

version 2.69 (sub 0), revision b'60991'. b'Release'
build date: b'2013-10-29', b'15:34:08'
platform: b'Linux:64bit'

I guess that sdfgeoff was using also.

I will test r60995 for linux and if it fail I will report the bug in blender bug tracker

edit:
Bug tracker link

https://projects.blender.org/tracker/index.php?func=detail&aid=37412&group_id=9&atid=306

Hmm. I’m using exactly the same as you cotax: 2.69.0 r60995, 64 bit version, windows 8.1.

Would you mind sharing the level file that does work? I’d be interested to know what the difference is.

I have send you an pm with the blend

Thanks. I’ve got it, and I’ve found why your’s works and mine doesn’t.

Here it is:

  • The progress indicates the scenes that have been loaded.

    In my level I had only a single scene, so it was either loaded or not.
    Cotax’s blend had some overlay/underlay scenes, so it had the loading status working.

Adding an overlay scene to my blend made it start having progress.

I’m afriad I find that a little silly, I would prefer it to be object-wise progress rather than scene-wise, but I suppose I can deal with it!

That’s a little disappointing… haha

It would be great to have the ability to grab the total amount of objects in another scene in a separate .blend (using libloading), so we could manually calculate the percentage ourselves according to the number of objects loaded from the other scene.

The only other thing I’d think of doing is actually naming the .blend the number of objects in the scene, something like, level2_293, and then manually change that number if you change the number of objects in your scene… However, this means one scene per .blend. I think that’s manageable though…

Any other way to make a progress bar?