iPhone - Drawing 2D Shapes
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 开发者_如何学Pythonable 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
Cocos2D is ultimately OpenGL so a possibility would be to add the functionality you are looking for manually. Perhaps add a ccDrawPoly
function with parameters to determine whether it should be filled or not. You should be able to find a great deal of documentation on doing polygon fills in OpenGL.
精彩评论