Drawing a line or rectangle on a cocos2d layer

Can you tell me what is the best way to draw a line or rectangle on the stage using Cocos2d ios4 iphone.

Still tried Texture2d, but it looks more like a brush and not very good. I tried to draw a line using the draw method, but the previous line disappears when I draw another line.

In principle, you need to draw several horizontal, vertical, inclined beams. Please suggest. Any code will help a lot.

The code for drawing using the texture below:

CGPoint start = edge.start;
            CGPoint end = edge.end;
            // begin drawing to the render texture
            [target begin];

            // for extra points, we'll draw this smoothly from the last position and vary the sprite's
            // scale/rotation/offset
            float distance = ccpDistance(start, end);
            if (distance > 1)
            {
                int d = (int)distance;
                for (int i = 0; i < d; i++)
                {
                    float difx = end.x - start.x;
                    float dify = end.y - start.y;
                    float delta = (float)i / distance;
                    [brush setPosition:ccp(start.x + (difx * delta), start.y + (dify * delta))];
                    [brush setScale:0.3];
                    // Call visit to draw the brush, don't call draw..
                    [brush visit];
                }
            }
            // finish drawing and return context back to the screen
            [target end];

The rendering is not very good. with slanted lines, because scaling affects quality.

Greetings

+3
source share
2 answers

:

-(void) draw
{
    CGSize s = [[Director sharedDirector] winSize];

    drawCircle( ccp(s.width/2,  s.height/2), circleSize, 0, 50, NO);

, . , , . , .

+2

draw :

-(void) draw {
    // ...
}

openGL cocos2d openGL.

: draw. , openGL, , . , schedUpdate.

, - :

-(void) draw {
    glEnable(GL_LINE_SMOOTH);
    glColor4ub(255, 0, 100, 255);
    glLineWidth(4);
    CGPoint verts[] = { ccp(0,200), ccp(300,200) };
    ccDrawLine(verts[0], verts[1]);

    [self drawSomething];
    [self drawSomeOtherStuffFrom:ccp(a,b) to:ccp(c,d)];

    [someObject doSomeDrawingAsWell];
}

cocos2d-iphone:

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:draw_update?s [] = schedule # draw

+2

All Articles