0

for ループがあり、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];
}

ありがとう

4

1 に答える 1

0

私のカウンターが適切にインクリメントされていなかったことが判明し、問題は単に次の行で画像に一意のキーを与えていないことにありました

CCSprite* answerMenuNormalSprite = [CCSprite spriteWithCGImage:graphImage.CGImage key:   [NSString stringWithFormat:@"answerMenuNormalSprite_%f", i]];
于 2012-05-09T09:09:45.557 に答える