Large world and loading objects

Hi,
I have a large world (3200x3200), I created this world using Tilemap, now I want to add foods on this world so the player will be able to eat them, but when I add foods to the map (there are so many foods) game gets slow and it seems it can’t handle all the objects.
I am looking for the best workaround for this.
What do you do in your own games? do you load objects by camera movements? what is the best way to do it?

There’s a good introduction to Tilemap culling in a previous dev log here.

You can also search around and take a look at numerous tile-based Phaser boilerplates.

I couldn’t find anything.
I will appreciate a straight forward answer.

I guess the post #1192 has your solution.

My tilemap doesn’t cause any performance issue, the physical objects I add into the tilemap cause it.
I am searching for a way to add physical objects inside the game without affecting performance.

Ooh. I see.

Then you should use setVisible(true OR false).

Just check if food is within the camera’s view and set setVisible(true) else false.

From the docs:

setVisible(value)
Sets the visibility of this Game Object.
An invisible Game Object will skip rendering, but will still process update logic.

You can also test setActive(true OR false). I can’t remember which one I used in a similar case.
See the docs.