Cocos2d iPhone CCClippingNode 不做剪辑 [英] Cocos2d iPhone CCClippingNode doesn't do the clip
本文介绍了Cocos2d iPhone CCClippingNode 不做剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我尝试在其上绘制图像和孔的代码.(代码来自cocos2d测试项目)
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];
所有图片都可以在cocos2d测试项目中找到.
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?
推荐答案
问题是我没有正确设置我的 CCGLView.我必须将深度格式设置为 GL_DEPTH24_STENCIL8_OES 而不是值 0.
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.
这篇关于Cocos2d iPhone CCClippingNode 不做剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文