lunes, 2 de abril de 2012

Cocos2D - Dibujar cuadrícula


Dibujamos una cuadricula de tamaño kTileSize definido como constante en el .h.



- (void)draw

{

   // get the device screen size.
    CGSize winSize = [[CCDirector sharedDirector] winSize];

    // set line smoothing
    glEnable(GL_LINE_SMOOTH);

    for (int i=4; i<winSize.height; i++)
    {
        CGPoint point1 = ccp(i*kTileSize, winSize.height - kTileSize);
        CGPoint point2 = ccp(i*kTileSize, kTileSize);

        // set line smoothing
        glEnable(GL_LINE_SMOOTH);

       
        // set line width
        glLineWidth(0.4f);

        // set line color.
        glColor4f(0, 0, 0, 1.0);

        ccDrawLine(point1, point2);

    }
   

    for (int i=0; i<winSize.width; i++)
    {

        CGPoint point1 = ccp(winSize.width - kTileSize, i*kTileSize);
        CGPoint point2 = ccp(kTileSize, i*kTileSize);


        // set line smoothing
        glEnable(GL_LINE_STRIP);


        // set line width
        glLineWidth(0.4f);


        // set line color.
        glColor4f(0, 0, 0, 1.0);

        ccDrawLine(point1, point2);

    }    

}