使用绘图功能突出显示高分

时间:2013-07-19 04:13:02

标签: objective-c opengl-es cocos2d-iphone

我已经实现了一个高分图层,现在我想在高分榜中突出显示一个新条目。这是我当前的绘图功能,但它不起作用并多次出现此错误:

OpenGL错误0x0501 in - [CCSprite draw] 530

绘制功能:

- (void)draw {
    [super draw];

    if(currentScorePosition < 0) return;

    ccDrawColor4F(0.0f, 0.0f, 0.0f, 0.2f);

    float w = 320.0f;
    float h = 27.0f;
    float x = (320.0f - w) / 2.0f;
    float y = 359.0f - currentScorePosition * h;

    GLfloat vertices[4][2];
    GLubyte indices[4] = { 0, 1, 3, 2 };

    vertices[0][0] = x;     vertices[0][1] = y;
    vertices[1][0] = x+w;   vertices[1][1] = y;
    vertices[2][0] = x+w;   vertices[2][1] = y+h;
    vertices[3][0] = x;     vertices[3][1] = y+h;

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    kmGLPushMatrix();

    glVertexAttribPointer( currentScorePosition, 2, GL_FLOAT, GL_FALSE, vertices, 0 );

    glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
    kmGLPopMatrix();

    ccDrawColor4F(1.0f, 1.0f, 1.0f, 1.0f);
}

1 个答案:

答案 0 :(得分:0)

而不是手动openGL调用绘制原语,而是使用Cocos2d调用。

void ccDrawSolidPoly( const CGPoint *poli, NSUInteger numberOfPoints, ccColor4F color );

例如,这是我的自定义绘图:

-(void) draw {
    CGPoint vertices[16];

    vertices[0] = ccp(0,radius);
    vertices[1] = ccp(0,radius*(1-kappa));
    vertices[2] = ccp(radius*(1-kappa),0);
    vertices[3] = ccp(radius,0);

    vertices[4] = ccp(size.width-radius,0);
    vertices[5] = ccp(size.width-radius*(1-kappa),0);
    vertices[6] = ccp(size.width,radius*(1-kappa));
    vertices[7] = ccp(size.width,radius);

    vertices[8] = ccp(size.width,size.height - radius);
    vertices[9] = ccp(size.width,size.height - radius*(1-kappa));
    vertices[10] = ccp(size.width-radius*(1-kappa),size.height);
    vertices[11] = ccp(size.width-radius,size.height);

    vertices[12] = ccp(radius,size.height);
    vertices[13] = ccp(radius*(1-kappa),size.height);                   
    vertices[14] = ccp(0,size.height-radius*(1-kappa));                   
    vertices[15] = ccp(0,size.height-radius);    

    CGPoint polyVertices[4*cornerSegments+1];
    appendCubicBezier(0*cornerSegments,polyVertices,vertices[0], vertices[1], vertices[2], vertices[3], cornerSegments);
    appendCubicBezier(1*cornerSegments,polyVertices,vertices[4], vertices[5], vertices[6], vertices[7], cornerSegments);
    appendCubicBezier(2*cornerSegments,polyVertices,vertices[8], vertices[9], vertices[10], vertices[11], cornerSegments);
    appendCubicBezier(3*cornerSegments,polyVertices,vertices[12], vertices[13], vertices[14], vertices[15], cornerSegments);
    polyVertices[4*cornerSegments] = vertices[0];

    CCNode *node=[self getChildByTag:13435];

    if(!node)
    {
        CCDrawNode *draw = [[[CCDrawNode alloc] init] autorelease];

        [draw drawPolyWithVerts:polyVertices count:4*cornerSegments fillColor:ccc4f(fillColor.r, fillColor.g, fillColor.b, fillColor.a) borderWidth:2.0 borderColor:ccc4f(1.0, 0.5, 0.5, 0.8)];

        [self addChild:draw z:0 tag:13435];
    }
}