How do I select a sprite from a spritesheet at runtime?

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

We are working on a game that uses a lot of tilesets. We have some questions about how to optimally work with spritesheets in Godot.

1. How do we efficiently select a new sprite from the spritesheet at runtime?
We want to change the sprite of a tile. Should we just set the TextureRegion to the correct tile, or is that not optimized if a lot of sprites change at the same time?
2. Can we check if a sprite in the spritesheet is empty?
Since we plan to have variations of our sprites, there is a chance that regions of the spritesheet are empty. What would be the best way to detect this?

Example of a small spritesheet with empty tiles. We would want to randomly select one of the variations, while making sure it never selects an empty tile.

3. How should we handle large amounts of sprites in Godot?
We are planning to have a lot of different biomes in our project. Would it be best to organise each biome in it’s own spritesheet? Should we combine all of them in one massive spritesheet, or should each tile be it’s own file? What is the optimal way to handle this in Godot?