[Request] Geometry shape object

New releases and general discussions.

Post » Tue Mar 31, 2009 4:56 pm

Basically an object that would draw a geometric shape of choice - rectangle, triangle, circle, polygons, whatever, with a very small footprint and innate collision mask. Transparent or filled.

Why not just draw one in sprite? Well, if you need something like a circle with radius of 256 pixels, the texture takes 512x512 pixels regardless of content or blank space. Annoying. Plus it doesn't scale too well!

The uses are many - to simply draw circles, polygons or whatever for many purposes (range overlay, firing arc for turrets etc.) - should be scalable (vector!).

There you go. Up for the challenge? :)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Mar 31, 2009 5:01 pm

You have to use textured sprites for circles anyway. DirectX doesn't provide any better way to draw circles other than putting one on a texture and drawing that, which is exactly what Sprite does. If you draw a fairly big, white circle (I wouldn't go bigger than 512x512 to save VRAM), you can colour it with the filter, and set the width/height to change its size. It'll still look nice.

You can use Box for a rectangle/square too!
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Mar 31, 2009 5:05 pm

That seems rather wasteful to draw, say, dozens of circles to represent weapon ranges, arcs and so on. Hmm, I should be fine by using template sprites, I guess; just worried about the rendering speed when there is a lot of stuff overlapping on screen.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Mar 31, 2009 5:45 pm

As I said, there's no better, or less wasteful, way. If you're creating <100 of these objects, I doubt you'll ever notice an FPS difference.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Mar 31, 2009 7:40 pm

i agree with ashley; your graphics card only needs to load the texture once, and putting it on a few dozen sprites will barely impact performance.

for those cases where you need really big diameter circles, you could use distorted sprites as a workaround ( example ). note that this will impact render performance more than a simple sprite, because the graphics card needs to process more vertices. but it's still a viable alternative if you don't have enough vram, dislike blown-up blurry pixels yet don't mind aliased edges.

this is by no means a comfortable way to do it, but if you really need it, i guess you could bend sprites into other geometric shapes as well.
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Tue Mar 31, 2009 10:34 pm

I don't think mesh distortion would work well for a larger circle. You'd need too many vertices for it to be efficient (remember 4 vertices is equivalent to 1 sprite). Textures are the way to go.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Mar 31, 2009 11:55 pm

depending on the circle diameter, you'd only have to build the segment that is actually visible; but you're right, piling vertices for smooth edges is a performance hog.

another idea would be to use quarter-circle textures & build a circle out of 4 sprites. that way, you could achieve smooth antialiased circles with a diameter of up to 8192px, given a limit of 4096px square for textures on most graphic cards.

(this won't suffice! its less than 9000!)
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Wed Apr 01, 2009 7:57 am

Well, problem is that sprites don't scale too well, especially if I want the thickness to remain the same (like 1-2 pixels), scaling it up makes edges thicker, scaling it down makes edges thinner... you get the idea. Plus you get ugly bumps if you scale stuff up (despite linear filtering).

But yeah, I'll have to use sprites of different sizes, no big deal. ;)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 4 guests