2012-05-08 5 views
0

for 루프가 있고 for 루프 내에서 다음 작업을 수행합니다.이 작업은 내 차트 배경에 선 그래프를 작성하지만 선의 동일한 이미지를 표시합니다. 데이터가 다르더라도 각각의 배경에 정확히 똑같습니다.iOS CGContext는 for 루프에서 선 그래프를 그립니다.

UIGraphicsBeginImageContext(test.size); 

CGContextRef c = UIGraphicsGetCurrentContext(); 
CGContextFlush(c); 

CGContextSetAllowsAntialiasing(c, true); 

CGContextTranslateCTM(c, 0, test.size.height); 
CGContextScaleCTM(c, 1.0, -1.0); 

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); 

CGFloat components[] = {0.0, 0.0, 1.0, 1.0}; 

CGColorRef color = CGColorCreate(colorspace, components); 

CGContextSetStrokeColorWithColor(c, color); 

CGContextMoveToPoint(c, 0, 0); 

     if(maxPoints > 0) 
     { 
      float xSpacing = (float)330.0f/(float)[allScorePointsSubset count]; 
      int currentPoint; 
      float currentX; 
      float currentY; 

      for (int j = 0; j < [allScorePointsSubset count]; j++) 
      { 
       NSString *currentPointString = [allScorePointsSubset objectAtIndex:j]; 
       currentPoint = (int)[currentPointString intValue]; 

       if(currentPoint < 0) 
        currentPoint = 0; 

       currentX = (j+1)*xSpacing; 
       currentY = currentPoint/100.0f * 200.0f; 

       CGContextAddLineToPoint(c, (int)currentX, (int)currentY); 

       } 

     } 

    CGContextStrokePath(c); 
    CGColorSpaceRelease(colorspace); 
    CGColorRelease(color); 

    UIImage *graphImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 


    CCSprite* answerMenuNormalSprite = [CCSprite spriteWithCGImage:graphImage.CGImage key: [NSString stringWithFormat:@"answerMenuNormalSprite_%f", i]]; 
      [answerMenuNormalSprite setPosition:ccp(176,66)]; 


    [[background objectAtIndex:0] addChild:answerMenuNormalSprite z:0 tag:i]; 

사람이 내가 잘못하고있는 무슨 어떤 아이디어를 가지고이 다음과 같은 방법으로 그것은 내 카운터가 제대로 증가되지 않았 음을 밝혀

-(void)draw 
{ 
    [super draw]; 
} 

감사

답변

0

해야 않으며, 문제는 다음 줄에 이미지에 고유 한 키를 제공하지 않는 것입니다.

CCSprite* answerMenuNormalSprite = [CCSprite spriteWithCGImage:graphImage.CGImage key: [NSString stringWithFormat:@"answerMenuNormalSprite_%f", i]]; 
관련 문제