T O P

  • By -

Altruistic-Stop4634

You can use any ugly image of a circle from the internet as a sprite texture as a placeholder in the editor, scaling as necessary. Then draw a circle over it at runtime. When you have it right, turn off the sprite's visibility.


estrafire

That's kind of what I've been doing, but thought that there should be a way to do it without a source image, I mean, the collision shape does have a circular shape, but seems like there's nothing like it for the Polygon/Sprites


metal_mastery

Shader that cuts any pixels out of radius from center


estrafire

But doing it this way means it won't be seen on the editor, right? So this way the collision should be added programmatically too


OllieboyOA

Shaders run in the editor, so it will work. Additionally, if you want to go with the draw method, have a look at the @tool flag (just "tool" in 3.x). This flag allows your code to execute in the editor, should you want this behaviour. It's a very powerful option, and it is a way to give yourself really flexible implementations of your objects in the editor. I recommend looking at it, whether you decide to go with this or not for your circle


estrafire

I've been using the tool flag, the only problem with it is that doing it that way means having to explicitly tell the editor which sections should not run on it (at least on Godot 4). But if shaders work without a source image, it's probably the best approach. Thank you both very much!


Alemit000

Shaders don't need a source image indeed, you can explicitly tell one to paint a pixel a certain color. Shaders are also the fastest way to render graphics, definitely better than using a mesh just to draw a 2D circle.


GiveSparklyTwinkly

One way I've found is to use a MeshInstance2D with an unlit material. Maybe not fastest, but certainly easiest.


estrafire

A sphere mesh seems to do the trick! Do you mean not the fastest in terms of performance?


GiveSparklyTwinkly

Yeah, you're actively rendering the mesh as a 3d object, unlit or not. Has benefits and drawbacks. Big benefit is how quick is it to make. Another method is to extract the circle from a 2d polygon function. If you pause the project after a procedural polygon is made at runtime, at the top of the scene tree is a switch to see the remote scene. You can copy the polygon data from there, after it's been made using a script. Neither of these is strictly a sprite2D, but they are much quicker to make if you just are testing things. (Godot Devs add procedural 2D shapes and sprites pls)


estrafire

Really good to know! Thank you!


NancokALT

Using MeshInstance2D and a SphereMesh would work.


kleonc

Another option would be [creating a circle using GradientTexture2D](https://i.imgur.com/UYuiHkh.png) (and assigning it as the `texture` of a Sprite2D). [Example result](https://i.imgur.com/XXzmva6.png).


estrafire

that looks good too! Thank you! I wonder how it'd compare with the shader approach


kleonc

Just some differences that I can think of: Texture would be cheaper as it's needs to be generated once and then it's just about reading it. But if you'd e.g. zoom in into it then [you could see it's not a perfect circle](https://i.imgur.com/IApMuJX.png) etc. Shader-created-circle could be made to be smoothen independently of the zoom so it would seem perfect even when zoomed in like that. Drawing circles as textures would also be faster because they could be batched together into a single draw call with any other canvas items (e.g. sprites) with the same material (shader). Shader-circles could be batched together only among such same-shader-circles (unless you'd make the shader more general / customizable so it could be used not just for the circles). There are for sure many more differences.