Cocos2d iPhone CCClippingNode doesn't do the clip

半腔热情 提交于 2020-01-15 09:14:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18981202/cocos2d-iphone-ccclippingnode-doesnt-do-the-clip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!