![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | StefanoGrossiNature |
In my 2d game there is a map with many Nodes (let’s say they could be 150/200 or more for very large maps),and the camera can move dynamically anywhere in the map at any time (it can jump in any area at any frame).
What i need to do is to draw only nodes that are inside the screen area(camera) and disable all that are off-screen,but i need to keep them in memory(just disable their draw and their execution or godot processing them).
How can i do it?
I’ve read many approach and methods but i am still not sure wich one to use.
My idea is to just remove() them from the scenetree and attach the newones before the frame is rendered,but how can i do it? Wich is the best approach?
I will be very thankful if someone can show me a correct approach to use and i will test it.
Thank you in advance.
Is setting their visibility to false not good enough for what you are trying to accomplish?
bloodsign | 2021-02-11 23:04
My actual approach is:
when the camera move to a new position i am removing nodes wich are not inside the screen and add the new ones. But it’s not in sync with the frame redraw.
I guess setting visibility to false will be a better approach,but godot will still process those nodes? (i mean calling their callbacks etc?)
StefanoGrossiNature | 2021-02-12 10:10
well, dynamically removing and adding nodes, depending on the size of those nodes might cause some small lag spikes?
I’m not entirely sure myself. My thinking is, wouldn’t it be better to keep them in memory rather than destroying them?
I would suggest to use the [debugger]. On [Monitor] Tab, you can check items on the list such as FPS, Memory, that is being used when the game is running.
You can see how much impact removing and adding your nodes does, and compare it if you are just setting nodes visibility to false.
bloodsign | 2021-02-12 11:42
My approach is not to unload them from memory but just removing them from the SceneTree (and then adding them again),this is actually not causing a lag (but i have to test it in a better way,so i am not sure).
My actual issue is:
1- how to sync it with the frame rendering (i need to add/remove them just BEFORE the new frame render)
2- Leaving them allocated will cause godot to still process them (cpu) ? Maybe signals…callbacks…some loops…etc?
If i solve this i am done.
Hope now it’s more clear.
StefanoGrossiNature | 2021-02-12 12:09