How to instance multiple sprites from the same script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By marcorexo

Hi,

I am new to Godot and would like to create multiple instances of the same sprite programatically in a scene at random x,y coordinates. Searching the web I found that it’s possible to instance multiple scenes but this seems a bit too much for this task?

Can I instance multiple sprite nodes using a script? Or is it possible to use a single sprite node with multiple textures and coordinates?

Thanks for your help.

:bust_in_silhouette: Reply From: i_love_godot

If you only want to draw the textures at different points and won’t be keeping track of their positions, you could use custom drawing with draw_texture() and pass in random positions. Custom drawing in 2D.

Other than that, you can just create a loop to create a set number of sprites and you can control the texture and position of each of them. Depends on your needs.

Hope this helps :slight_smile: