I've found something strange which looks like a bug to me with the way that CCDrawNode.DrawPolygon works. I've simplified the problem down to drawing a triangle within an enclosing rectangle (I've had similar problems when using complex polygon shapes).
The problem is that a very narrow triangle has it's end drawn way outside the rectangle even though all points of the triangle are easily within the rectangle.
Here is the code that shows the problem:
CCLayer layer = new CCLayer(); CCDrawNode node = new CCDrawNode(); List<CCPoint> points = new List<CCPoint>(); float left = 50.0f; float right = 600.0f; float bottom = 200.0f; float top = 900.0f; float inset = 50.0f; float triWidth = 85.0f; node.DrawRect(new CCRect(left, bottom, right - left, top - bottom), CCColor4B.Transparent, 5.0f, CCColor4B.Red); points.Add(new CCPoint(left + inset, top - inset)); points.Add(new CCPoint(right - inset, bottom + inset)); points.Add(new CCPoint(left + inset, top - triWidth - inset)); node.DrawPolygon(points.ToArray(), points.Count, CCColor4B.Gray, 5.0f, CCColor4B.White); layer.AddChild(node); AddChild(layer);
I've attached three screenshots where the only difference is the variable triWidth, at a value of 20 the end is way offscreen, at a value of 85 it's outside the rectangle but onscreen and a value of 200 does what I'd expected and is completely within the rectangle.
The triangle apex point "new CCPoint(right - inset, bottom + inset)" is the same in all examples towards the bottom right of the rectangle. It is the base width of the triangle at the upper left of the rectangle that is being changed.
Is this a bug or is this down to some sort of border join problem as if I change the border from 5.0f to 0.0f then the triangle is within the rectangle even with a triWidth set at 20.0f which with the border goes way offscreen.