Information

Author:
    DevonX
Rating:
    8.2 (6 votes)
Type:
    Example
Language:
    GM 6
Reviews:
    None
Submitted:
    February 12, 2007
Dev - DB/form (refering to updated - check code)
Download:
    DOWNLOAD (487)
Dev - make AJAX
Screenshots (0)
Dev - Also, on form submission, use GD to resize the image as a new thumbnail file
There were no screenshots provided
Dev - In the submission form, you can now upload a banner image
Sprite To Polygon
This is a simple engine that takes a sprite and it draws a polygon on a surface that outlines the sprite, this engine is not very sound though. I will be updating it sometime with a better version. Right now, complex sprites can cause glitches, i have done all i can to prevent infinite loops, so you won't get those often, prolly just once in a while. What it does is for every 4 degrees, it moves out from the center of the sprite until it hits the transparency color, then it adds a point to the polygon there.


Target platforms:



Simple yet clever. As you said, a bit unstable on occasion but in all other aspects rather nice. 9/10
Posted by Juju February 12, 2007 12:49 - 10.5 years ago
| [#01]

A different approach could be to:
1.1 start a for loop running through all pixels in the sprite
1.2 run a flood fill like script that adds all transparent pixels with adjacent not tranparent pixel(s) to a list
1.3 if the transparent pixel is already in a list continue, otherwise create a new list, start a new flood fill and add all the transparent pixels to the new list.

That was part 1.
Part 2:
2.1 Start a for loop running though the lists one at a time
2.2 for each tranparent pixel find the two nearest pixels in the same list (let's call them prev and next), and store those. (I guess a two dimensional array would do) You could even be advanced and add an argument to determine how many pixels should be skipped (see part 2b)

Part 2b:
2b.1 You're doing this instead of the loop in part 2
2b.2 for one tranparent pixel find the argument num nearest pixels in the same list, and store the ones furthest away in a whole new list. Now do the same for those 2
2b.3 repeat this process until all pixels has either been checked or added to the new list
2b.4 delete all pixels from the old list that didn't make it to the new list

Part 3:
3.1 draw lines from all the remaining pixels to their nearest ones.
*note I realize that this would draw double as many lines as needed but what the hey...

(I haven't tested this)
Posted by SpectreNectar February 12, 2007 15:08 - 10.5 years ago
| [#02]

Pretty cool, I may find this useful.
Posted by OL February 12, 2007 15:10 - 10.5 years ago
| [#03]

Pretty interesting. Although I found it rather pointless to use in a game unless you prove me wrong. Works rather well though, few unstabilities though as you said. And the outline isn't perfect either, but that's ok because it's pixels...8/10
Posted by Crane-ium February 12, 2007 18:23 - 10.5 years ago
| [#04]

Good, but there are a few glitche and it is not entirely accurate.
7/10
Posted by gtvg February 13, 2007 16:55 - 10.5 years ago
| [#05]

alright spectre, ill experimant with some of ur suggestions
Posted by DevonX February 13, 2007 19:28 - 10.5 years ago
| [#06]

This seems to do the same as "create polygon auto" from GMPhysics. Only your code is MUCH more compact: I think create polygon auto is 3 pages long, yours only 26 lines. And it sure is useful (if, like me, you are using GMPhysics where such Polygons are required for the generation of collision bodies)
Posted by Melancor February 21, 2007 3:52 - 10.5 years ago
| [#07]

I didnt check out the coding, but neat
Posted by ussyless February 27, 2007 9:27 - 10.5 years ago
| [#08]

Melancor, I do remember that function from GMPhysics, I did not use that, because that wouldn't be right. I never even thouroughly went though that script. This is entirly my approach. I thought of it durring math class . [:)]
Posted by DevonX April 08, 2007 19:28 - 10.4 years ago
| [#09]

Hey i got a use for it, to easily generate polygon shapes in polygon shooters like asteroids, were the shape would look crumby through rotation the poly would keep a nice figure.
Posted by Blood Ninji July 26, 2008 12:41 - 9.1 years ago
| [#10]

Recent Activity
 
Active Users (0)