[4.7 Stable]-Fastest Method To Make Many Identical Sprites Stored In An Array Not Shown On The Screen Anymore(But Not Unloaded)?

Godot Version

v4.7.stable.official [5b4e0cb0f] - CachyOS KDE Plasma(Wayland) x86_64 Linux on a mini PC

Question

Hi,

Trying to further optimize our playing game screen for our puzzle game project…
What is the fasted method to make many identical Sprites(in an array) not show on the screen anymore?

With no frame limit, we are only getting about 120 Frames Per Second, would like to improve that.

We currently move all the identical Sprites off of the screen in a for loop, but it is rather slow.
You can see our GDScript source code for the above below:

Let us know, thanks!

SS

for index in range (0, 9):
for indexStart in range(2000, 18000, 2000):
for indexTwo in range (0, VisualsCore.PieceSpriteCurrentIndex[index]):
RenderingServer.canvas_item_set_transform( VisualsCore.Sprites.ci_rid[indexStart+indexTwo], Transform2D().translated( Vector2(-99999, -99999) ) )

The term you want to search for is called “Object Pooling”

What part is slow? The loop itself? Or the overall performance?

If you have many identical objects, use multi instancing instead of a canvas item per sprite. Also there’s RenderingServer::canvas_item_set_visible() which may be preferable to moving the items off screen.

Hi,

Can someone recommend a place on the Internet to post the playing game screen function?
We won’t upload to GitHub until feature frozen Beta 1.
Let us know, with your help we will make something amazing.

SS

Sorry, please look at function below on Paste.io

https://pastes.io/AvBgZfRy

That code scares me
:face_with_peeking_eye:

Hi,

Sorry the code “scares you”?
Perhaps someone else can help us?

SS

I think it may scare most of people who could potentially help you.

The lord of chaos reigns over this code.