The documentation for newPolygon() mentions a couple of things you can do to screw up the polygon vertices info, but says nothing about order. Yet, the order appears to make a difference if you have a stroke. The strokeWIdth documentation describes how the stroke is drawn vis a vis the object’s edges but does not indicate that it will cause vertex order to matter.
To see what I’m talking about, there has to something to make it clear where the polygon edges are landing. The following example uses newPolygon() to draw a simple triangle four times, each time rotated by 90 degrees so that the result would logically be a solid rectangle. Which it is, for one direction of the triangle vertices, but for the other direction a gap appears between the four triangles.
local function CreateEdge(Index, Width, Counter) assert(Index \> 0 and Index \< 5) local function Anchor(obj) obj.anchorX=.5; obj.anchorY=1; end -- create triangle as a polygon local Triangle if Counter then Triangle = display.newPolygon(0, 0, { 0, 0, Width/2, -Width/2, -Width/2, -Width/2, } ) else Triangle = display.newPolygon(0, 0, { 0, 0, -Width/2, -Width/2, Width/2, -Width/2, } ) end Triangle.fill = {0,1,1} Anchor(Triangle) local Result = Triangle Result:rotate((Index-1) \* 90) Triangle.stroke = {1,1,0} Triangle.strokeWidth = 1 return Result end local Group1 = display.newGroup() for i = 1,4 do Group1:insert(CreateEdge(i, 50, true)) end Group1.x, Group1.y = 200, 200 local Group2 = display.newGroup() for i = 1,4 do Group2:insert(CreateEdge(i, 50, false)) end Group2.x, Group2.y = 400, 400
The result is two sets of four triangles, one with a gap between the triangles and one without. The only difference in how they are drawn is the order of the vertices in the call to newPolygon(). Note that if you don’t have a stroke, this code just produces two solid rectangles, as expected.
I can’t find documentation that explains this behavior. I’m stumped.