1

这是我如何尝试在其上绘制图像和孔的代码。(代码来自cocos2d测试项目)

    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];

所有图片都可以在 cocos2d 测试项目中找到。

问题是图像出现了,但上面没有孔。我做错了什么?

4

1 回答 1

1

问题是我没有正确设置我的 CCGLView。我必须将深度格式设置为 GL_DEPTH24_STENCIL8_OES 而不是值 0。

于 2013-09-26T06:53:32.867 回答