Tuesday, November 5, 2013

Cocos2D-X: Drawing Rectangle with Border

This needs to be done in 2 draws, one to draw the border and the other to draw a solid rectangle.

Example code:

void MyLayer::draw()
{
CCPoint p1 = ccp(x1,y1);
CCPoint p2 = ccp(x2,y2);

   ccColor4F color;
   color.a = 1.0;
   color.r = 0;
   color.g = 0;
   color.b = 0;
   ccDrawSolidRect(p1,p2, color);
   
   ccDrawColor4B(255, 255, 255, 255);
   ccDrawRect(p1,p2);
}

p1 being the bottom left corner of the rectangle and p2 being the top right.

In order for this to be called, the function needs to be override the "draw" function of the parent.

No comments:

Post a Comment