How do I keep a layout running while the next one is loading

Get help using Construct 2

Post » Mon Aug 01, 2016 10:59 pm

Hey, at the moment, to load the heaviest layouts, I use another layout that displays a text and an animation while the next layout is loading. However, my problem is that everything stops as soon as the next layout starts loading, including the animation. That gives the layout a froze effect, and that's quite problematic. So is there a way to have the layout continue to run as long as the next layout is not fully loaded yet?
Image
B
34
S
6
G
2
Posts: 224
Reputation: 3,355

Post » Mon Aug 01, 2016 11:15 pm

Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Tue Aug 02, 2016 10:08 am

Well thanks. I'll try to make something like this. However, it's still quite problematic. Can't we have a feature like "preload layout" and when the layout is fully loaded, have an event "On layout loaded". I may ask this as a plugin request.
Image
B
34
S
6
G
2
Posts: 224
Reputation: 3,355

Post » Tue Aug 02, 2016 10:43 am

Why would a player need to keep playing while the next level is loading?
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Post » Tue Aug 02, 2016 11:31 am

Well, imagine this:
I have a loading screen that has an animation in it or even a minigame, or anything to keep the player focused.
Right now, I can't have this, because you cannot preload another layout in background. So to have this you have to "simulate" a loading screen, make it do what you want, and then go to another layout. However, this is problematic, because, if you have a layout that needs a lot of memory, the current layout completely freezes while the other layout loads, and when it finally shows, you have a quite big FPS drop.
Having a way to preload another layout before going to it would fix those problems.

In my case, sometimes, a layout can take up to 10 seconds to load properly.
Image
B
34
S
6
G
2
Posts: 224
Reputation: 3,355

Post » Tue Aug 02, 2016 4:19 pm

There may be a way, but it is a bit more cumbersome. In addition to using the method described by backendfreak, you can have by default all your sprites on your layout mimimalistic or blank/low resolution. Then after you load into the layout. but while your layout is still obscured by the loading overlay, use the sprite objects load image from URL to replace the fast loading sprites with your actual sprites. Your overlay should be able to run as this is happening, so you can set up your minigame first, or show progress.

An additional benefit is you can use on (final) image loaded to start your actual layout, which is better than just waiting an arbritraty amount of seconds.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Tue Aug 02, 2016 8:49 pm

Yeah, that may do the trick, but is indeed a lot more complicated. But, having placeholders for big objects and replace them in my custom loading screen is a good idea. However, that may make the level design a bit more complicated, as big object tend to have more animations, or bigger resolutions. And if they do have a lot of animations, you may want to have multiple instances of this object and each one running a different animation on start. It would take a bit of coding to have this done along with the placeholder. But that's very complicated.
Image
B
34
S
6
G
2
Posts: 224
Reputation: 3,355

Post » Tue Aug 02, 2016 9:38 pm

I see two options here:

1. As described in my tutorial mentioned above. Basically you show loading screen at the end of the first layout and you hide it once everything is loaded/stable on the second layout. It doesn't speed up the loading process but at least you get rid of that "freeze" feeling.

2. C2 engine clears the memory while switching between layouts, but it keeps the objects which are used both in the layout you are now and the one you are switching to. So basically all common objects remain in the memory and there is no need for the engine to reload them. You can use this fact and load the assets you need in the next layout just before switching to another layout (or during gameplay... up to you).
I think you don't need to place the second layout assets in your first layout. Never tried it myself but simply spawning those objects from the code should do the job.
There's another trick here. Keep in mind that C2 engine does not load objects which are outside visible area, so spawning an object at position -9999, -9999 won't work. Also invisible objects are not being rendered. So you need to do some kind of dirty trick like:
a) spawn object at any position
b) set it's opacity to 1 (almost invisible)
c) set it's position to overlap visible area (it doesn't have to be the middle of the screen, it can be partially visible somewhere in the corner)
d) wait 0.017s (that's the duration of 1 tick), not sure if this's gonna be needed but I believe it will to force the engine to load/render the asset
e) set it's position somewere far away

Might look complex but if you prepare good generic code then it's just a matter to setup some lines in event sheet for each layout.
ImageImageImage
B
27
S
16
G
73
Posts: 974
Reputation: 41,157

Post » Wed Aug 03, 2016 12:07 am

Well, thanks. Your second idea is really good. What's eating up most of my memory is a screen object that displays a lot of different animations.
I'll see if I can somehow preload it anywhere, and make it global so it is not deleted. That may not be a good idea though. I'll try what you said, and let you know.
Image
B
34
S
6
G
2
Posts: 224
Reputation: 3,355

Post » Wed Aug 03, 2016 12:18 am

I don't understand. Why does a player need to be playing a minigame, for 10 seconds, while the next level loads?
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Next

Return to How do I....?

Who is online

Users browsing this forum: Laura_D, plinkie and 21 guests