作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用Cocos2d画一个更粗的圆:
glLineWidth(20);
ccDrawCircle(self.ripplePosition, _radius, 0, 50, NO);
但这就是显示的内容(注意它看起来像是由 4 个不同的段创建的):
http://i.stack.imgur.com/jYW4s.png
我尝试将段数增加到更大的值,但结果是相同的。
这是 Cocos2D 中的错误吗?关于如何实现“完美”圆有什么想法吗?
以下是 cocos2d 2.0rc2 中 ccDrawCircle 的实现:
void ccDrawCircle( CGPoint center, float r, float a, NSUInteger segs, BOOL drawLineToCenter)
{
lazy_init();
int additionalSegment = 1;
if (drawLineToCenter)
additionalSegment++;
const float coef = 2.0f * (float)M_PI/segs;
GLfloat *vertices = calloc( sizeof(GLfloat)*2*(segs+2), 1);
if( ! vertices )
return;
for(NSUInteger i = 0;i <= segs; i++) {
float rads = i*coef;
GLfloat j = r * cosf(rads + a) + center.x;
GLfloat k = r * sinf(rads + a) + center.y;
vertices[i*2] = j;
vertices[i*2+1] = k;
}
vertices[(segs+1)*2] = center.x;
vertices[(segs+1)*2+1] = center.y;
[shader_ use];
[shader_ setUniformForModelViewProjectionMatrix];
[shader_ setUniformLocation:colorLocation_ with4fv:(GLfloat*) &color_.r count:1];
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segs+additionalSegment);
free( vertices );
CC_INCREMENT_GL_DRAWS(1);
}
最佳答案
我使用了 ccDrawCircle 的稍微修改版本,它工作得很好(比使用 Sprite 和调整 Sprite 大小要好得多):
void ccDrawDonut( CGPoint center, float r1, float r2, NSUInteger segs)
{
lazy_init();
const float coef = 2.0f * (float)M_PI/segs;
GLfloat *vertices = calloc( sizeof(GLfloat)*4*segs+4, 1);
if( ! vertices )
return;
for(NSUInteger i = 0;i <= segs; i++) {
float rads = i*coef;
GLfloat j1 = r1 * cosf(rads) + center.x;
GLfloat k1 = r1 * sinf(rads) + center.y;
vertices[i*4] = j1;
vertices[i*4+1] = k1;
rads+= coef/2;
GLfloat j2 = r2 * cosf(rads) + center.x;
GLfloat k2 = r2 * sinf(rads) + center.y;
vertices[i*4+2] = j2;
vertices[i*4+3] = k2;
}
[shader_ use];
[shader_ setUniformForModelViewProjectionMatrix];
[shader_ setUniformLocation:colorLocation_ with4fv:(GLfloat*) &color_.r count:1];
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei) 2*segs+2);
free( vertices );
CC_INCREMENT_GL_DRAWS(1);
}
关于ios - 锯齿状 ccDrawCircle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11045463/
使用Cocos2d画一个更粗的圆: glLineWidth(20); ccDrawCircle(self.ripplePosition, _radius, 0, 50, NO); 但这就是显示的内容(
我是一名优秀的程序员,十分优秀!