2013-09-24 52 views
1

這裏是我的代碼,我試圖畫一個圖像和一個洞。 (該代碼是從所述的cocos2d測試項目)Cocos2d iPhone CCClippingNode不做剪輯

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中測試項目中找到。

問題是圖像出現,但沒有洞。我做錯了什麼?

回答

1

問題是我沒有正確設置我的CCGLView。我必須將深度格式設置爲GL_DEPTH24_STENCIL8_OES而不是數值0.

+0

任何有關將設置爲android的位置的想法?我無法在android目錄中的任何位置找到深度格式屬性。 – CodyMace