Good afternoon,
I’m building some polygons to procedurally draw some stairs, and sometimes I get an invalid polygon message:
WARNING: Polygon could not be generated. The polygon outline is invalid, possibly due to holes or self-intersection.
I’ve read quite a bit about the subject, trying to find the problem. Since the polygons were being procedurally generated, I printed out some of the list of vertices, so I could reliably replicate the problem. I managed to get a set of vertexes that consistently gave the error, but there weren’t any duplicate vertices or intersecting lines. Moreover, I tried removing vertices one by one, and some vertices would remove the warning when missing (though you could remove any one of those, and the others would no longer be offenders).
In any case, I’m running out of ideas of how or why this polygon is breaking, so I thought I’d post here and see if anybody could see what’s wrong.
This polygon will draw:
vertices = {
0, -10.164,
30.8, -10.164,
30.8, -20.328,
61.6, -20.328,
61.6, -30.492,
92.4, -30.492,
92.4, -40.656,
123.2, -40.656,
123.2, -50.82,
154, -50.82,
154, -60.984,
184.8, -60.984,
184.8, -71.148,
215.6, -71.148,
215.6, -81.312,
246.4, -81.312,
246.4, -91.476,
277.2, -91.476,
277.2, -101.64,
308, -101.64,
308, -111.804,
338.8, -111.804,
338.8, -121.968,
369.6, -121.968,
369.6, -132.132,
400.4, -132.132,
400.4, -142.296,
431.2, -142.296,
431.2, -152.46,
462, -152.46,
462, -162.624,
492.8, -162.624,
--492.8, -172.788,
--523.6, -172.788,
523.6, 1080,
0, 1080,
}
local newPoly = display.newPolygon( display.contentCenterX, display.contentCenterY, vertices )
newPoly.anchorY = 0
This, on the other hand, will not.
vertices = {
0, -10.164,
30.8, -10.164,
30.8, -20.328,
61.6, -20.328,
61.6, -30.492,
92.4, -30.492,
92.4, -40.656,
123.2, -40.656,
123.2, -50.82,
154, -50.82,
154, -60.984,
184.8, -60.984,
184.8, -71.148,
215.6, -71.148,
215.6, -81.312,
246.4, -81.312,
246.4, -91.476,
277.2, -91.476,
277.2, -101.64,
308, -101.64,
308, -111.804,
338.8, -111.804,
338.8, -121.968,
369.6, -121.968,
369.6, -132.132,
400.4, -132.132,
400.4, -142.296,
431.2, -142.296,
431.2, -152.46,
462, -152.46,
462, -162.624,
492.8, -162.624,
492.8, -172.788,
523.6, -172.788,
523.6, 1080,
0, 1080,
}
local newPoly = display.newPolygon( display.contentCenterX, display.contentCenterY, vertices )
newPoly.anchorY = 0
And once again, this one will draw.
vertices = {
0, -10.164,
30.8, -10.164,
--30.8, -20.328,
--61.6, -20.328,
--61.6, -30.492,
--92.4, -30.492,
--92.4, -40.656,
--123.2, -40.656,
--123.2, -50.82,
--154, -50.82,
154, -60.984,
184.8, -60.984,
184.8, -71.148,
215.6, -71.148,
215.6, -81.312,
246.4, -81.312,
246.4, -91.476,
277.2, -91.476,
277.2, -101.64,
308, -101.64,
308, -111.804,
338.8, -111.804,
338.8, -121.968,
369.6, -121.968,
369.6, -132.132,
400.4, -132.132,
400.4, -142.296,
431.2, -142.296,
431.2, -152.46,
462, -152.46,
462, -162.624,
492.8, -162.624,
492.8, -172.788,
523.6, -172.788,
523.6, 1080,
0, 1080,
}
local newPoly = display.newPolygon( display.contentCenterX, display.contentCenterY, vertices )
newPoly.anchorY = 0
For clarity’s sake, I’ve commented out vertices instead of removing them, so it’s more obvious what has been removed in each case.
To make it even more baffling, it also draws correctly if I leave all points in place, but reduce the vertical height of the polygon by making the last two vertices have 359 instead of 1080 as the y
coordinate.
523.6, 359,
0, 359,
Now I feel I might be missing something incredibly obvious, but I’m at a loss at to where else to look or what more to consider. Any help would be really appreciated.
Thanks in advance!