Best way to make a colored squares for in-game use

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

I see there is a ColorRect object but that one inherits from Control so I’m not sure if its best to use those in the actual game. Control stuff is meant for the interface mainly, correct?

Ive also seen draw_rect but that doesnt seem to return the rectangle. I want an actual object I can manipulate via a Tween node, etc etc. Basically I want something like a Sprite with a custom rectangle attached to it vs a real image texture. I’m hoping I don’t have to use an image editor in order to draw and export a square.

Other game engines ive used in the past allowed you to make custom shapes and use them as regular game objects which could be useful for creating prototypes etc.

:bust_in_silhouette: Reply From: Bernard Cloutier

Create a 1 pixel by 1 pixel white png image in paint. In Godot, place a sprite and set that png as its texture. In the inspector under CanvasItem/Visibility, set the field “Modulate” to your desired color. “Modulate” is unique to the node, so even if multiple sprites use the same png, they can be of different colors.

If you are intent on not using an image texture, then just select new GradientTexture on your sprite texture. Set the gradient width to 1 and the sizes of PoolFloatArray and PoolColorArray to 1 as well. Under PoolColorArray, select your color. Then just scale the sprite to the desired size.

I thought of this myself and thought it was a silly solution but if that’s the way you have to do it then I guess that’s the way you have to do it. Thanks for your response.

hamoom | 2020-01-23 17:30