Question

Here are my code how I am trying to draw an image and a hole on it. (The code is from the cocos2d test project)

    CCSprite *target = [CCSprite spriteWithFile:@"blocks.png"];
    target.anchorPoint = CGPointZero;
    target.scale = 3;

    CCClippingNode *outerClipper_ = [[CCClippingNode clippingNode] retain];
    outerClipper_.contentSize = CGSizeApplyAffineTransform(target.contentSize, CGAffineTransformMakeScale(target.scale, target.scale));
    outerClipper_.anchorPoint = ccp(0.5, 0.5);
    outerClipper_.position = ccpMult(ccpFromSize([CCDirector sharedDirector].winSize), 0.5);

    outerClipper_.stencil = target;

    CCClippingNode *holesClipper = [CCClippingNode clippingNode];
    holesClipper.inverted = YES;
    holesClipper.alphaThreshold = 0.05;

    [holesClipper addChild:target];

    CCNode *holes_ = [[CCNode node] retain];

    [holesClipper addChild:holes_];

    CCNode *holesStencil_ = [[CCNode node] retain];

    holesClipper.stencil = holesStencil_;

    [outerClipper_ addChild:holesClipper];

    [self addChild:outerClipper_ z:9999];


// Add the hole

    CCSprite *hole = [CCSprite spriteWithFile:@"hole_effect.png"];
    hole.position = [outerClipper_ convertToNodeSpace:ccpMult(ccpFromSize([CCDirector sharedDirector].winSize), 0.5)];

    [holes_ addChild:hole];

    CCSprite *holeStencil = [CCSprite spriteWithFile:@"hole_stencil.png"];
    holeStencil.position = [outerClipper_ convertToNodeSpace:ccpMult(ccpFromSize([CCDirector sharedDirector].winSize), 0.5)];

    [holesStencil_ addChild:holeStencil];

All the images can be found in the cocos2d test project.

The problem is that the images appear, but there is no hole on it. What I am doing wrong?

Was it helpful?

Solution

The problem was that I didn't setup my CCGLView correctly. I have to setup the depth format to GL_DEPTH24_STENCIL8_OES instead of the value 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top