How to create a CCSprite that is a Polygon shape
What I want is for the user to draw a polygon and for a sprite to be made in the shape of the polygon. I already have all the programming done for the user to create the polygon, so I can read the vertices of any image drawn. However, I seem to only be able to make sprites that are rectangular, using CGRectMake. Is there a way to create a sprite image from a file that is polygonal in shape. Like a CGPolyMake where I give it the 开发者_如何学编程vertices or something like that.
I don't know what shape the user will draw so I can't premake polygon sprites. Thanks for any help!
Cocos2D has no dedicated CCNode class for this purpose. You need to create a CCNode subclass and implement the draw-method yourself. That requires some knowledge about OpenGL ES.
You'll also have to triangulate the polygon so that you can fill it with a given texture. You could use this C++ code for that: http://www.flipcode.com/archives/triangulate.cpp
This thread in the cocos2d forum is very helpful: http://www.cocos2d-iphone.org/forum/topic/8142
精彩评论