iPhone - Drawing 2D Shapes

Posted by Hawdon on Stack Overflow See other posts from Stack Overflow or by Hawdon
Published on 2010-06-17T12:18:19Z Indexed on 2010/06/17 12:23 UTC
Read the original article Hit count: 313

Filed under:
|
|
|
|

Hi guys!

I have an array of 2D points which make an irregular polygon. What I want to do is draw the borders of it and then fill it with a color.

I am using Cocos2d to code the game around, but I have not found a fill function in Cocos2d, only the

ccDrawLine

and such.

Is there a simple way to draw filled shapes in Cocos2?

I have also noted that Core Graphics would work beautifully for this purpose, but I am not able to integrate it with Cocos2d. I put this in to the draw function of my CCLayer:

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, [[UIScreen mainScreen] bounds]);

And every time I run it i get this error:

<Error>: CGContextClearRect: invalid context

I really need to get this working...

Any ideas?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about graphics