This is an automated archive made by the Lemmit Bot.

The original was posted on /r/godot by /u/baksoBoy on 2024-09-17 10:57:29+00:00.


I’m generating a pretty large 2D world, where most objects like for examples trees and rocks will be their own individual sprite node. If I were to have them as nothing more than sprites, then my game will run pretty slowly (around 30 FPS). I however am using code for each sprite that runs every frame that changes its opacity in certain circumstances. If I were to run this code for all sprites just like that then my computer would probably explode, so what I have done is to add a VisibleOnScreenNotifier2D on each one of these sprites, making it so that the code that changes how they are rendered is only run if the sprite is on-screen. However even with this my game runs extremely poorly (around 4 FPS).

One idea I had for a solution would be to (if possible) completely disable all the logic and stuff that has to be processed for the spites if it is off-screen, however this obviously still comes with the problem of having to constantly detect if it comes on-screen again to resume the logic, so this doesn’t really sound possible.

My other idea (which I really don’t want to do if there exists a simpler approach) is to somehow store the information of all the sprites, and make it so that whenever the sprite is too far away from the player, it deletes itself and gets stored to some sort of list, and when the player moves, all the newly loaded areas check if they are supposed to have a sprite on them, and then re-generates them before they appear on-screen. This solution sounds pretty involved though, and I’m not entirely sure how I’m supposed to store the information of all the sprites in a way where it is very quick to check if a certain position should have a sprite on it or not (note that the coordinates are integers, so you can theoretically store all positions on the map, which you wouldn’t be able to do with floats).

Does anyone have any ideas for how I could reduce the lag?