【问题标题】:CGPath invisible on CCLayerCGPath 在 CCLayer 上不可见
【发布时间】:2012-01-29 17:20:41
【问题描述】:

我正在使用 Cocos2d。我正在尝试使用 CGPath 制作“轨迹”。 CGPath 在屏幕上,我已经对其进行了 NSLogged。 “轨迹”或 CGPath 不可见。

- (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);

}

“轨迹”需要动态生成。

我有几个不同的错误,如下所示:

<Error>: CGContextDrawPath: invalid context 0x0

任何帮助都会很好

【问题讨论】:

    标签: cocos2d-iphone core-graphics cgcontext cgpath cclayer


    【解决方案1】:
    //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();
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 2011-04-30
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多