Only load tiles near the player

How do I…

I made a big tilemap (10000x15000 pixels), how do I only load the tiles near the player so it doesn’t lag that much, now it’s unplayable.

What is the expected result

I’d like to load tiles near m’y player and not load the others.

What is the actual result

My game load every tiles and lags a lot.

Hi!

In my game (only the level 2 for now), my scene is about 10000 x 5000.
There are about 8000 instances of blocs or tiles of sprites.
There are rapidly loaded at the beginning: no slowing because i only use instances of some objects.

You must consider to reanalyse your project (ideal is before to begin your game)

A+
Xierra54

0000

How many objects? Though this shouldn’t matter - it’s more likely the events are causing an issue.

You can check this by running the analyser in debug mode and checking where most of the processing is taking place.

40 percent is taken by smooth camera and 40 percent by “Render”.

Instead of Smooth Camera you could use a simple tween. There is an action “Tween the camera position”, call it every frame with “easeOutSine” and duration 1 second, boom smooth camera movement. The extension has extra bells and whistles which you may not need.

I would think Lerp could be even more efficient, with no overhead that setting up the tween would have.


@Trowaway, do you have any “Repeat for each object” events that reference the tile objects?

No, there’s very little code, and not code at all referencing to tiles. Lacking time I just erased like 3/4 of the map, and I am now making different scenes to alleviate the burden of the processor. (It worked).

Edit: I also wanted to write this. Making different tilemaps will also reduce lag, because when you have one tilemap it’s loaded fully, when you have multiples tilemaps, only those near the screen would get loaded. I hope it makes sens.