My game has ‘menu’,‘options’,‘credits’ and ‘ingame’ screens (for now).
The basic ‘pseudocode structure’ is this:
#load menu assets (image, buttons, etc)
#buttons to go to 'menu2ingame', 'options' and 'credits'
#unload menu assets
#load options assets (images, buttons, etc)
#unload menu assets
#load credits assets (images, buttons, etc)
#unload assets for menu
#unload assets for options
#unload assets for credits
#unload assets for in game models, etc
#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:
fadeOut(2) function interval
function interval that removes all the menu assets
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?
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)
I see this is confusing, I tried to recreate the problem here in a very simple code: mediafire.com/?gij1nzzqim5
Well maybe it doesnt recreate the problem…
The manual.py is from the Panda3D manual.
In my.py 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)
fade screen to complete black
wait until step 1 is done
unload not needed assets
load the models needed for next scene/level
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.
fade screen to black as an interval, thus allowing doing other things parallel
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
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.
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.
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
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