python and panda3d questions

My game has ‘menu’,‘options’,‘credits’ and ‘ingame’ screens (for now).
The basic ‘pseudocode structure’ is this:

def menu():
    #load menu assets (image, buttons, etc)
    #buttons to go to 'menu2ingame', 'options' and 'credits'

def options():
    #unload menu assets
    #load options assets (images, buttons, etc)

def credits():
    #unload menu assets
    #load credits assets (images, buttons, etc)

def ingame():
    #unload assets for menu

def options2menu():
    #unload assets for options

def credits2menu():
    #unload assets for credits

def ingame2menu():
    #unload assets for in game models, etc

def menu2ingame():
    #fadeOut, unload assets, load game assets,
    #fadeIn, all in a Sequence


Unlike the ‘options’ and ‘credits’ screen, the amount of models, images, sounds, gui elements to be removed and loaded in menu2ingame() are alot, so it freezes few seconds. I decided to fade the screen to black, do that ‘loading/unloading’, and then fade back, so it would look nicer.
So in menu2ingame() I created a Sequence with intervals to fadeOut, unload all the menu assets, load most of the ingame assets, fadeIn.
SO there are 4 intervals in the sequence:

  1. fadeOut(2) function interval
  2. function interval that removes all the menu assets
  3. function interval that loads the ingame assets
    4, fadeIn(2) function interval
    Also I added a delay interval of 2 seconds between the 1st and 2nd intervals for fading to work, but still, the models that are loaded in the 3rd interval are loaded before the fading finishes (hardly starts), so there is the same freeze effect. I probably misunderstood sequences.
    What can I do?

(Un-)Load your models asyncronously while fading out and initiate the fade-in first if all async-tokens signalize that they’ve done their job.

I don’t understand…

So… any help?

Sorry, haven’t noticed your last reply.

So what exactly don’t you understand?

wouldn’t be simpler to put a black png card in front of the screen (I mean in render2d) as a curtain and do whatever you need and then fade that curtain at the end of all?

Thats almost what I do:
Please read my 1st post, this is how the sequence looks like:

a = Sequence(1,wait(2),2,3,4, name="name")

I mentioned the intervals in the 1st post. The thing is my game freezes before the screen goes to black, but the interval for fading is before the interval for loading models.

I dont know what ‘asyncronously’ means.

I’m usually hard to get things but here I find really harder to get what you’re asking for - often is just a matter of the meaning of words though.
asynchronous = not synchronized with something
fade in = gradually change status into something else
fade out = gradually change status from something else
I guess your problem is you’re using the fade functions in the opposite place - just use fade in on sequence step n.1 (in place of fade out) and vice versa use fade out at the last sequence step (in place of fade in)

that’s my best advice for what I get here.

I see this is confusing, I tried to recreate the problem here in a very simple code:
Well maybe it doesnt recreate the problem…
The is from the Panda3D manual.
In I tried to do that with transitions. As you can see FadeIn doesnt really work here (bug?).
If you change the lines

ival1 = Func(fadeIn)
ival2 = Func(fadeOut)


ival2 = Func(fadeIn)
ival1 = Func(fadeOut)

then I think that will actually recreate my problem: the screen fades to black when the sound hasnt finished yet - the same way my game freezes because of loading assets, when the screen hasnt faded to black yet, even though that interval is after the fading interval…

the problem you encounter is, i guess, that loading models stops the game loop and it looks like if your game pauses for a moment (or few seconds, if you load many models in a row)

Simple solution:

  1. fade screen to complete black
  2. wait until step 1 is done
  3. unload not needed assets
  4. load the models needed for next scene/level
  5. fade out the black curtain and show your scene to the player

here’s a way using asynchronous loading. that is loading things in background while not disturbing the game loop, that runs all your tasks, manages events and so on.

Advanced solution:

  1. fade screen to black as an interval, thus allowing doing other things parallel
  2. unload your assets while fading out and after the fade-out is finished. this can be done by using asynchronous (un)loading - look into the reference for more detail
  3. a task checks if the unloading is all done already (by looking up their flags/tokens) and it starts a batch of new loaders, which load up your needed assets. here you can choose yourself if you use asynchronous loading. as there’s nothing to update on the screen anyways, you don’t have to care about visual response. the curtain most probably is all black at this moment.
  4. after everything is loaded, you draw the curtain

pros and cons of the advanced solution:
[color=green]+ using asynchronous loading and/or “fade-screens” your application stays responsive, thus allowing you to fade-out or -in or to show an animated loading screen or something.
[color=green]+ you can make advantage of multicore CPUs for loading multiple models simultaneous
[color=red]- you need a task that checks if the asynchronous loading has finished and which manages the next steps

I hope this answers your questions. If not, try to ask more precise, maybe.

Have a nice day

here you go Anon: see below

Well did you read this?

I use that idea

are you sure you did read my 2nd point?

‘Advanced solution’? Shouldn’t I get the simple one to work before I try that?

D’ouh. With ‘2nd point’ I meant the second point of the simple solution. Sorry for writing so fuzzy.

Hmm, well yeah thats my problem, the models are (un)loaded before the fading finishes, but it fades back after the few models are loaded :confused:
Shouldn’t a sequence work like that? Why shouldn’t I check if the asset loading is done before fading back?

anyway, how would you suggest to find out if its done?
Now I use a

middleinterval = Wait(2) #same 2 seconds as for fading... 

I have a feeling I’m finally gonna get this fixed.
If no I’ll upload a real clone with placeholder models.

check this out - I wasn’t happy with the former code and made a complete snippet - I used my first option with the black curtain and it works as you asking for without the need of that Transition class.

Well that is the same effect as with transitions, I wanted to make one myself when I found out about the Transitions class.
So there is a bug when using transitions huh?
PS. You can post this in the snippets section, I’m sure people will find it useful

Before loading, try to :


and after loading :


happy to hear this solved - yep at the end I found that Transitions object a bit glitchy and then I dropped for a my simpler former idea.
PS: as you suggested I published the snippet