Hey I want to create a circle shaped polygon2D and I will be putting textures on it. However I can not find any information on how to do so. I want a circle object like wheel that will roll and will change it's texture for wheel and other stuff. How can I achieve this thank you all. Also 1 method I tried is shaping a circle sprite in to polygon2d but it reduces great performance and it does not result in an actual circle instead a 1500~edged polygon.

in Engine

–1 vote

If you use CollisionShape2D, you can selected a CircleShape2d

by (49 points)

Yes I know that, but I am trying to achieve a circle texture base that I will be putting on textures. Is there a way to put textures on CollisionShape2D ?

so the numSides is the number of sides/faces and the perimeter length is the length of the perimeter.

``````func generatePolygonV2(numSides, perimeterLength):
var lineLength : float = perimeterLength/numSides
var lineAngle : float = -360.0000000000/numSides
var currentAngle : float = 0.0000000000

var newPolygon = Polygon2D.new()
var polygonVectors : PoolVector2Array

for i in numSides:
var newVector

if i == 0:
currentAngle += lineAngle
polygonVectors.append(newVector)
else:
currentAngle += lineAngle
polygonVectors.append(newVector)

newPolygon.polygon = polygonVectors
newPolygon.color = Color(1,0,1)
polygon = newPolygon
``````

something like this? The only problem with my method is the polygon generated is not centered. I have an idea on how i could fix that but yeah i'm lazy.

by (14 points)

Here is some code that would generate a circle polygon:

``````func generate_circle_polygon(radius: float, num_sides: int, position: Vector2) -> PoolVector2Array:
var angle_delta: float = (PI * 2) / num_sides
var vector: Vector2 = Vector2(radius, 0)
var polygon: PoolVector2Array

for _i in num_sides:
polygon.append(vector + position)
vector = vector.rotated(angle_delta)

return polygon
``````

This would generate a polygon circle of a certain `radius` with a certain `num_sides` with `position` as the center point.

by (22 points)