half-potato
half-potato

Reputation: 1027

CCRenderTexture not clearing with color correctly and skipping pixels

I am using CCRenderTexture to draw some points pixel by pixel. However, it is skipping pixels and not clearing the background correctly. It does not matter what color I choose when I clear it. I always get a white background. It randomly skips pixels that I try to write to the texture. Here's the code:

    size = [[CCDirector sharedDirector] winSize];

    mapOfTheLongLostGoldenSpoon = [Map2D newMapWithDimensions:16 :16];

    [mapOfTheLongLostGoldenSpoon set:100 :102];
    [mapOfTheLongLostGoldenSpoon set:102 :100];
    [mapOfTheLongLostGoldenSpoon set:103 :100];
    [mapOfTheLongLostGoldenSpoon set:104 :102];

    layer = [CCSprite spriteWithFile:@"PixelSprite.png"];
    layer.color = ccc3(0, 0, 0);

    points = [mapOfTheLongLostGoldenSpoon getPoints];

    mapTexture = [[CCRenderTexture alloc] initWithWidth:[mapOfTheLongLostGoldenSpoon width] height:[mapOfTheLongLostGoldenSpoon height] pixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    mapTexture.position = CGPointMake([mapOfTheLongLostGoldenSpoon width], size.height-[mapOfTheLongLostGoldenSpoon height]);
    mapTexture.scale = 2;
    mapTexture.anchorPoint = ccp(0, 0);
    [mapTexture beginWithClear:25 g:255 b:25 a:255];

    layer.visible = TRUE;

    for (int x = 0; x < sizeof(points); x++) {
        NSLog(@"%f, %f", points[x].x, points[x].y);
        layer.position = points[x];
        [layer visit];
    }

    layer.visible = FALSE;

    [mapTexture end];

    free(points);

    [self addChild:mapTexture];

You can trust that the points provided are fine. Example point: point 100, 102 will not render.

Link to image: https://i.sstatic.net/xWiXB.png

Take note of the color I clear with and the fact that I try to render 4 pixels and only 3 appear.

The simulator is simulating a iPhone Retina 3.5 inch.

The image is 110 by 110.

Thanks for the help!

EDIT: Added missing code and an image.

Upvotes: 0

Views: 104

Answers (1)

Allen S
Allen S

Reputation: 1042

Your clear method call is incorrect. The values are between 0.0 and 1.0, not 0 and 255. Try:

[mapTexture beginWithClear:0.1f g:1.0f b:0.1f a:1.0f];

Currently what you have would cause it to appear all white. I hope this helped.

Also why are you doing sizeof(points)? sizeof returns the size in bytes not the number of elements in the array.

Upvotes: 1

Related Questions