Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在cocos2d-x中使用颜色绘制圆形填充?_Android_C++_Cocos2d X - Fatal编程技术网

Android 如何在cocos2d-x中使用颜色绘制圆形填充?

Android 如何在cocos2d-x中使用颜色绘制圆形填充?,android,c++,cocos2d-x,Android,C++,Cocos2d X,我是cocos2d-x的新手,我正在尝试用里面的颜色画一个圆圈。 我在网上搜索,找到了一些代码。我尝试了下面的代码,但它只画了一个带颜色边框的圆圈。我的cocos2d-x版本是2.1.5,我正在android上使用它。 我还尝试使用以下方法更改边框的宽度:glLineWidth(2)但在我的cocos2d-x中找不到此方法。如何在圆中添加颜色以及如何更改圆的边框宽度 cocos2d::ccDrawColor4B(0, 255, 255, 255); cocos2d::ccDrawColor4F(

我是cocos2d-x的新手,我正在尝试用里面的颜色画一个圆圈。 我在网上搜索,找到了一些代码。我尝试了下面的代码,但它只画了一个带颜色边框的圆圈。我的cocos2d-x版本是2.1.5,我正在android上使用它。 我还尝试使用以下方法更改边框的宽度:glLineWidth(2)但在我的cocos2d-x中找不到此方法。如何在圆中添加颜色以及如何更改圆的边框宽度

cocos2d::ccDrawColor4B(0, 255, 255, 255);
cocos2d::ccDrawColor4F(0, 255, 255, 255);
cocos2d::ccDrawCircle( ccp(100/2, 100/2), 50, CC_DEGREES_TO_RADIANS(90), 50, false);

不确定从哪个
cocos2d-x
版本可用,但您应该有绘制实心圆的特定方法-

void drawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
看一看夜间课程。

在课堂上,你可以画圆、线和多边形

void drawDot(const CCPoint & pos,float  radius, const ccColor4F & color)

在给定半径和颜色的位置绘制一个填充圆,只需在CCDrawingPrimitives中添加一个新方法即可。它与
ccDrawCircle
相同,只是
glDrawArrays
使用
GL_三角形_扇
而不是
GL_线_条

在标题中,添加:

 void CC_DLL ccDrawSolidCircle( const CCPoint& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
在.cpp文件中,添加:

 void ccDrawSolidCircle( const CCPoint& center, float radius, float angle, unsigned int segments, bool drawLineToCenter)
 {
lazy_init();

float scaleX = 1;
float scaleY = 1;

int additionalSegment = 1;
if (drawLineToCenter)
    additionalSegment++;

const float coef = 2.0f * (float)M_PI/segments;

GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
if( ! vertices )
    return;

for(unsigned int i = 0;i <= segments; i++) {
    float rads = i*coef;
    GLfloat j = radius * cosf(rads + angle) * scaleX + center.x;
    GLfloat k = radius * sinf(rads + angle) * scaleY + center.y;

    vertices[i*2] = j;
    vertices[i*2+1] = k;
}
vertices[(segments+1)*2] = center.x;
vertices[(segments+1)*2+1] = center.y;

s_pShader->use();
s_pShader->setUniformsForBuiltins();
s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &s_tColor.r, 1);

ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

 #ifdef EMSCRIPTEN
setGLBufferData(vertices, sizeof(GLfloat)*2*(segments+2));
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
 #else
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
 #endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segments+additionalSegment);

free( vertices );

CC_INCREMENT_GL_DRAWS(1);
 }
void ccDrawSolidCircle(常量CCPoint¢er、浮点半径、浮点角度、无符号整数段、布尔drawLineToCenter)
{
lazy_init();
float-scaleX=1;
float-scaleY=1;
int additionalSegment=1;
如果(drawLineToCenter)
附加段++;
常量浮点系数=2.0f*(浮点)M_PI/段;
GLfloat*顶点=(GLfloat*)calloc(sizeof(GLfloat)*2*(段+2),1);
如果(!顶点)
返回;
for(unsigned int i=0;我使用();
s_pShader->setUniformsForBuiltins();
s_pShader->SetUniformLocation with 4FV(s_nColorLocation,(GLfloat*)和s_tColor.r,1);
ccGLEnableVertexAttribs(kCCVertexAttribFlag_位置);
#ifdef EMSCRIPTEN
setGLBufferData(顶点,sizeof(GLfloat)*2*(分段+2));
glVertexAttribPointer(kCCVertexAttrib_位置,2,GL_浮动,GL_假,0,0);
#否则
glVertexAttribPointer(kCCVertexAttrib_位置,2,GL_浮动,GL_假,0,顶点);
#endif//EMSCRIPTEN
glDrawArrays(GL_三角形_扇,0,(GLsizei)段+附加段);
自由(顶点);
CC_增量_GL_图纸(1);
}

感谢您提供ans,但此方法采用3.0alpha0-preWell,您可以尝试复制该方法。主要区别在于使用
gldrawArray
调用
GL\u TRIANGLE\u FAN
而不是
GL\u LINE\u STRIP