CGPath invisible on CCLayer

290 views Asked by At

I am working with Cocos2d. I am trying to make a "trail" using a CGPath. The CGPath is on screen I have NSLogged it. The "trail" or CGPath isn't visible.

- (void)drawRect:(CGRect)rect
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);

    CGContextSetLineWidth(context, 20.0);

    CGContextMoveToPoint(context, p0.x, p0.y);
    CGContextAddLineToPoint(context, p1.x, p1.y);

    CGContextStrokePath(context);

}

The "trail" needs to be dynamically generated.

I have a few different errors that look like:

<Error>: CGContextDrawPath: invalid context 0x0

Any help would be nice

1

There are 1 answers

0
Liolik On
//try this

- (void)drawRect:(CGRect)rect
{ 
    UIGraphicsBeginImageContext(self.boundingBox.size);
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);

    CGContextSetLineWidth(context, 20.0);

    CGContextMoveToPoint(context, p0.x, p0.y);
    CGContextAddLineToPoint(context, p1.x, p1.y);

    CGContextStrokePath(context);
    UIGraphicsEndImageContext();

}