kloot
January 6, 2024, 8:43pm
1
Godot Version
4.2.1
Question
I have a Area2D with a CollisionPolygon2D child. I’m trying to show the shape of this Area2D in-game by assigning it a color or a texture (not for debug purposes but for actual in-game use).
I see lots of folks have tried to do this, but I have not been able to get it to work:
https://godotforums.org/d/18855-how-to-give-a-color-to-area2d
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
lai32290
Hi guys, I’m creating a paiting game, so I have the image as the background, and I wanna create some Area2D as paiting area.
And when I click on the Area2D, it should paint the CollisionShape2D with the selected color.
How can I paint CollisionShape2D?
Thanks
I can’t see why it didn’t work.
If it is a rectangle area then just add a ColorRect as a child of the Area2D and set the size and extents the same as the CollisionShape2D.
kloot
January 6, 2024, 11:11pm
3
kloot:
CollisionPolygon2D
The problem is that it’s not a rectangle but a CollisionPolygon2D (with quite a complex polygon shape).
I think you can use _draw
method for this case.
1 Like
kloot
January 7, 2024, 1:02am
5
Thank you @supernovafiles , I was able to do the following (C#):
public override void _Draw()
{
base._Draw();
DrawColoredPolygon(myCollisionPolygon2D.Polygon, highlightColor);
}
2 Likes
system
Closed
February 6, 2024, 1:02am
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.