0 votes

As a learning project, I'm recreating the old Atari classic Asteroids in Godot. That has always been my "Hello World" app when I start playing with a new game engine... ;^)

Originally, I just created typical transparent PNG files with white outlines for the typical Asteroids assets (ship, rocks, enemy, ...).

But, I have the vector coordinates for all of those assets and noticed that Godot has a simple, Polygon2D node that I can use to consume the coordinates in place of a Sprite node.

A few quick changes and I nearly have what I want, using my original vector coordinates and Polygon2D nodes in place of my sprites. Except...

I don't see a way to simply draw the polygon outlines. They're always solid filled. Ideally, the Polygon2D would just have a boolean "filled" property and maybe a "strokeWidth" property, but that doesn't seem to be the case. With that in mind, I assume if I continue down the vector path, I'll need to draw my own polygons in-game?

Advice appreciated.

If I need to draw my own polygons, a push to the appropriate classes / methods would be great.

And, FWIW, I'm really enjoying Godot.

Thanks.

in Engine by (10,932 points)

1 Answer

0 votes
Best answer

There is Line2D to draw lines with many options, but it would still require some scripting to make it render a closed polygon (and more if the polygon is hollow). I think at the moment the best option is to draw them yourself. Nobody seems to have requested that feature on Polygon2D, so maybe it's time?

by (27,962 points)
selected by

Thanks for the input. I'll take a look at Line2D.

Also, I just made a feature request here:

https://github.com/godotengine/godot/issues/30667

@Zylann,

Looking at Line2D, I think it's capable of exactly what I want/need. It seems I can simulate a closed, outline-only polygon by just adding one more point to the end of the coordinate array that repeats the first point's position.

Additionally, I can set the color and the line width. Really, that's all I think I need at the moment.

With that in mind, I guess I don't understand some of the potential issues you eluded to above. I'm probably missing the points you were trying to make.

I will say that the final in-game appearance of the Line2D drawn items don't seem to be quite as "clean" as the sprites they replaced. I'm not yet sure why that is. Perhaps something to do with anti-aliasing, which Line2D doesn't seem to support (?).

It seems I can simulate a closed, outline-only polygon by just adding one more point to the end of the coordinate array that repeats the first point's position.

There is actually more to do for this to be accurate. If you create a fake point just to close the line, you will produce overdraw. This node claims no overdraw at all, which allows to make it transparent without artifacts. You should be fine if you don't use transparency or textures.

What do you mean by "clean"? If you mean anti-alias, I'm not sure if it's even supported in 2D, at least for polygons. Line2D uses polygons to generate its visual, not "lines". That allows it to have round caps, texture and configurable thickness.
To draw actual OpenGL 1px-thick lines, you could use draw_line() inside a _draw() function.

There is actually more to do for this to be accurate. If you create a fake point just to close the line, you will produce overdraw. This node claims no overdraw at all, which allows to make it transparent without artifacts. You should be fine if you don't use transparency or textures.

Understood. Yeah, since I'm not using any transparency, this isn't an issue for me, but I see how it could be for other cases.

What do you mean by "clean"?

Like I said above, I'm not really sure what I mean by that yet, but it definitely doesn't look quite as nice after replacing the sprites with Line2D. I think it may be AA related, but I need to run the two variations in parallel to get a better feel. I will say the Line2D version has more motion-flicker than the sprite-based version, but it's more than that. I'll post some pics if I find anything more definitive.

If you mean anti-alias, I'm not sure if it's even supported in 2D, at least for polygon

I've seen a few discussions on this. If that's the case, why does Polygon2D support an Antialiased property? And, related, why does Line2D not have such a property?

To draw actual OpenGL 1px-thick lines, you could use draw_line() inside a _draw() function.

Thanks - good to know. Though, I may just switch back to sprite-based representations for both simplicity and quality.

I've seen a few discussions on this. If that's the case, why does Polygon2D support an Antialiased property? And, related, why does Line2D not have such a property?

I tried this property and it didnt have any effect ^^" In fact, when looking through the source code, it's not even used by anything. Maybe it used to work in an old version but none of the redone renderers supported that.
There is no such parameter on Line2D maybe for the same reason, but maybe nobody thought of adding it either.

I tried this property and it didnt have any effect

Ah, interesting. Perhaps it has a moderate placebo effect.

TIcks the AA option...
"Aah, yeah, that's much better..."
Never looks back...

While the pursuit of vector-based rendering has been interesting academically, I'll probably go back to the sprite-based representations. Really, there's no reason not to. I just found it interesting to reuse the original vector coords I had in some other, long-ago incarnation of this game...

Thanks for the continued input.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.