What is the simplest way to set the Sprite for the class's object at instantiation

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

I want to a create a lot of objects from a 2D class (don’t move don’t collide) and each has a different individual sprite that never needs to be changed- not changed between each other. Clarification- essentially 9 different sprites later they change their color that is all they do. What is the simplest way to do that? Do I need a sprite array?

:bust_in_silhouette: Reply From: dethland

Your question is a little bit ambiguous, but here are my thoughts.

Your problem: Want to change sprite color(or other parameters) when adding the sprite instance to the scene.

To do that you need to change parameters (ex: the color of the sprite) of the instance before you use add_child to the scene.

It may looks like this:

var sprite = load("your path")
var color_list = [all color you want]
for i in range(0,9): # or any other loop is ok
    var temp_sprite = sprite.instance()
    temp_sprite.modulate = color_list[i]
    add_child(temp_sprite)

Not my question- at instantiation choose one sprite for the object (900 objects to create). Simplest way to do that. No tutorials that I have seen cover that.

cloa513 | 2021-10-24 21:36