0 votes

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.

asked Jan 23 in Engine by hamoom (35 points)

1 Answer

0 votes
Best answer

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.

answered Jan 23 by Bernard Cloutier (208 points)
selected Jan 23 by hamoom

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.