How to load part of the map or objects when you reach at a certain point? for performance reasons

I want to make my map bigger in the same scene and also improve performance so how can i load a part of the map only when reaching it

2 Likes

You could try slicing your background into pieces and create the backgrounds and other objects on the fly. You could place a transparent sprite near the area where the new map elements will be needed and create what’s needed on collision, and use the behavior “destroy when goes off screen” to make sure only the needed elements are loaded.

1 Like

Ok but how will i make the objects appear when I reach a point, what’s the event code for that

You can separate your map in external layouts (zones). When touching certain colliders, you unload the zones too far away and load the next zones using the create objects from external layout action.

1 Like

arthuro’s method is more efficient I think. Always good to know a new method.

If you use my method, you would use create object at position, and set the z order.

if you use arthuro’s method

1 Like

When I, with Multimedia Fusion, created a Canabalt game clone, i used the simple manner as described by Fiktoh and Arthur: i made the new obstacle objects by advance when the moving to left piece of background reached a certain X position (let’s say X -100). This new piece of background was created in an right outside place (X = width of scene + delta) and of course, i destroyed the left background which was no more seen.
I made of this manner also for the platform objects which also moving right to left, at the same speed of the moving scrolling background. Also, these object were destroyed by me when they are out of the screen at left.

Thanks anyway. But after an hour of searching i figured out what is external layout, but the problem is I have created my game level in Scene, so is there a way to copy part of my game level to external layout to use it for loading when i want? or is there a way to load part my level without using external layout.

I get it how to create object by name or position but i want to load the whole part of a level, it there a way for that? hope you get it.

I have created my game level in scene is there a way to copy part of the level in external layout, or i have to create my level all over again in external layout, so i can use it for loading when i want?

create the external layout
link it to the scene you want to copy from
open both the external layout and the scene in the editor
enter the scene, copy the items
enter the external layout, paste.

1 Like

Thanks for the help, it was pretty easy to copy, silly me

1 Like

I’ve been known to ask for features that were already there, so don’t feel too bad. :wink: I’m glad you posed the question, I didn’t know this method of using external layouts and I think it may be some use in a project I’m working on which has a bit of lag here and there.

strange but im getting way too much lag when the external layout loads, and yes i have removed that part from my scene

How many objects are you trying to load? and of what size?

I know usually gdevelop is really good at handling lots of objects (i’ve had over 2500 objects in a scene and runs good even on old laptop) but it tends to have a hard time with large files, like if you have high resolution backgrounds 4000x4000 pixels it’s harder to optimize.

Objects are almost 1000 and texture size for half of the objects are 600x100, and just one background 3000x3000, which is loaded from that start.

Originally when whole my level was in one scene the game ran smooth 60fps.
Now using the external layout ,as soos as the external layout loads the game lags like 5 fps.

Is this a bug or what

have you set the behavior “destroy when off screen” ?

no, let me try that…

That behavior “destroy when off screen” is another way of optimizing I will use that later, but why is “external layout” slowing my game that much rather than make it fast

I don’t know how your events are structured but you may need to limit the loading of the external layout.

For example, if the layout loads on collision with a character, and your character is in collision for 2-3 seconds, Gdevelop could be trying to load the layout every frame. You may need to add a way to limit the loading, with trigger once or a variable.

Maybe, i was thinking of that too

I have added when scene variable score is greater than 5 create objects from external layout