如何创建多边形形状的 CCSprite
我想要的是让用户绘制一个多边形并以多边形的形状制作一个精灵。我已经为用户完成了创建多边形的所有编程,因此我可以读取所绘制的任何图像的顶点。然而,我似乎只能使用 CGRectMake 制作矩形的精灵。有没有办法从多边形文件创建精灵图像。就像 CGPolyMake 一样,我给它顶点或类似的东西。
我不知道用户将绘制什么形状,所以我无法预先制作多边形精灵。感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cocos2D 没有专门用于此目的的 CCNode 类。您需要创建一个 CCNode 子类并自己实现绘制方法。这需要一些有关 OpenGL ES 的知识。
您还必须对多边形进行三角测量,以便可以用给定的纹理填充它。
您可以使用以下 C++ 代码:http://www.flipcode.com/archives/triangulate。 cpp
cocos2d 论坛中的这个帖子非常有帮助:http://www.cocos2d-iphone.org/forum/topic/8142
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