How to draw a filled circle in MonoGame?

Absolutely right!

1 Like

Sorry, you didn’t see it in context. It’s perfect for my needs:

He means the pixilation around the edges of the circle and, to be fair, I’m inclined to agree with him. I can definitely tell that circle has been scaled up. It looks like you’re using Anisotropic so at least it’s not hard edges, but it’s quite visible.

I think Martenfur’s proposal is the overall best in terms of performance and pretty good for visuals, but assuming you’re using a SpriteBatch approach to rendering, it’ll take a significant amount of refactor to switch everything over to using it.

To make the shader approach work, I think you would just need to create a new SpriteBatch and use a nested begin/end so you could call into the shader. This approach will give you perfect edges with any size circle. I’m just not sure how performant it will be. You would need to test.

To extend your current approach, you could do the mip-map method I suggested above. Create several circles at different texture sizes (32x32, 64x64, 128x128, 256x256, and 512x512), have your program select the one that is “closest” to the diameter of the circle you want to draw, scaling to the desired end result. For example, if you wanted a circle of diameter 200, your code would pick the 256x256 texture and scale it down to a 200x200 texture. This would give you cleaner (but not as good as Martenfur’s and not perfect like the shader), but should be pretty performant.

In the grand scheme of things though, it’s probably not worth the effort to fix. From your posts I know you’ve been working hard, pushing to get your game out. You have something that works, it’s probably a good idea to move on and come back to this later :slight_smile:

Not… really? He doesn’t have to replace the batch completely, he just needs to replace the vertexbach code with raw primitive drawing, or just use vertexbatch as a secondary batch - you can easily use several batches at once.

I did a quick experiment with the battle of Antietam (it is the smallest battlefield and, therefore, ranges are greatly scaled up):


And this works fine for me because I’m just showing the range of a unit with 25% opacity. BUT, it’s drawing outside the map. Is there a way to clip a sprite?

I thought you mentioned it didn’t preserve ordering. If he draws his circle over top his map and units, but under that tooltip, will that still work? If so then it should be just as easy to integrate as the shader method.

This is what we mean…

I highlighted the edges with a blue line. It’s very easy to see that you used a low resolution circle and scaled it up. Anisotropic filtering blends it a little bit, but it’s still pretty visible, especially in high contrast areas such as where it’s currently overlapping with the left-pane and the river.

New thread, please :slight_smile:

It does preserve ordering. Default spritebatch has fancier sorting methods based on z depth - those are not supported. It’s “first came - first served”.

1 Like

I guess I found that out. I made the z index for the red sprite really high (0.9) and it didn’t change the order of draw.