cocos2d-iphonecclayer

Drawing with cocos2d


I'm overriding the draw method of CCLayerColor to draw a border, but the color does not change. I've tried ccDrawXxxx and they all only ever use white as the color. I've also tried glColor4ub with the same effect. This is all I have in my draw method:

CGSize selfSize = [self contentSize];
float selfHeight = selfSize.height;
float selfWidth = selfSize.width;
CGPoint vertices[4] = {ccp(0.f, 0.f), ccp(0.f, selfHeight), ccp(selfWidth, selfHeight), ccp(selfWidth, 0.f)};

glColor4f(0, 0, 1.0f, 1.0f);
glLineWidth(4.0f);
ccDrawPoly(vertices, 4, YES);

Am I missing something? I'm using v2.0.


Solution

  • This should work:

    ccDrawColor(1, 0, 0, 1);
    ccDrawSomething(…);
    

    You shouldn't use the GLES 1.1 methods like glColor4f and glLineWidth in cocos2d 2.0. Maybe this somehow affects the GL state by causing OpenGL errors.