2
$\begingroup$

I have a loading bar with 100 frames. Most of what I can find for making a loading bar is what I've done (100 frame animation) and works with time. In other words, the loading bars load up independent of loading up objects and the scene. I am trying to create a loading bar that progresses as objects, properties, and parts of the scene are loaded. How can I have my 100-frame animation progress through the animation as parts of the scene are loaded? I am looking for a python script that could load up these parts and progress the loading bar. Thanks!

To make this a little quicker to answer: I am fine if you create the .py script with only as little as 2 frames as I will know how to add the rest - a 100 frame python script would be absurd to ask for an answer.

$\endgroup$

1 Answer 1

3
$\begingroup$

Scene loading

When a scene gets loaded the game will only do that and not refresh anything. The current (game) render will persist until the loading is completed.

Therefore your request will not do anything. You can't animate the render during loading.

LibLoad scene loading

You can load scene data from an external .blend file with LibLoad. The data will be merged into the current scene.

Synchronously

Per default it works like normal scene loading by showing the last render image until the load is complete = no animation.

Asynchronously

With the parameter async=True you can run the load over several frames.

The call provides you with a bge.types.KX_LibLoadStatus. From that you can read the current status of the load operation.

example [the code is untested]:

import bge

INTERNAL_PROPERTY_STATUS = "_internal.status"

def load(controller):
   '''Starts loading operation, stores the status in a property.'''
   status = bge.logic.LibLoad("demo.blend", "SCENE", async=False)
   controller.owner[INTERNAL_PROPERTY_STATUS] = status

def progressToValue(controller):
   '''Sets the value attribute of the first actuator to the progress from status.'''
   status = controller.owner.get(INTERNAL_PROPERTY_STATUS)
   if status == None:
      return

   actuator = controller.actuators[0]
   actuator.value = "'{}'".format(status.progress)
   controller.activate(actuator)

Be aware progress is a value from 0.0 to 0.1. You might want to scale it to your needs before using it.

Remark: I do not know if the progress shows more than 0.0 and 1.0 yet.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .