knagode
knagode

Reputation: 6125

Draw filled dynamic polygon in Cocos2D, iOS

How can i draw polygon with points read from NSMutableArray object in cocos2D framework?

I am able to draw polygon using this function: filled antialiased poly cocos2d

The problem is becouse points argument *(CGPoint poli) must be static object.

Any ideas or suggestions?

Upvotes: 2

Views: 2047

Answers (1)

brigadir
brigadir

Reputation: 6942

What is type of NSMutableArray objects? You need to extract raw data of points and set it as poli argument. If it's NSValue with CGPoint then:

NSMutableArray* yourPointsArray;
...
CGPoint* poli = malloc (sizeof (CGPoint) * [yourPointsArray count]);
for (uint i=0; i<[yourPointsArray count]; i++)
{
    poli[i] = [[yourPointsArray objectAtIndex: i] CGPointValue];
}
ccFillPoly (poli, [yourPointsArray count], YES);
free (poly);

Upvotes: 3

Related Questions