Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何用openGL处理cocos2d中的多掩模_Objective C_Opengl_Cocos2d Iphone - Fatal编程技术网

Objective c 如何用openGL处理cocos2d中的多掩模

Objective c 如何用openGL处理cocos2d中的多掩模,objective-c,opengl,cocos2d-iphone,Objective C,Opengl,Cocos2d Iphone,我想用一个矩形遮罩一个暗背景图像来突出显示一个区域。 遮罩纹理为: 渲染结果为: 但这不是我想要的。我需要它像这样(ps照片): 背景纹理是全屏大小的深色照片 遮罩纹理为40像素大小。所以,我想在渲染时移动它以获得不同的形状。 主要代码: CCSprite *textureSprite=[CCSprite spriteWithFile:@"bg_blank_alpha.png"]; CCSprite *maskSprite=[CCSprite spriteWithFile:@"bg_bo

我想用一个矩形遮罩一个暗背景图像来突出显示一个区域。 遮罩纹理为:

渲染结果为:

但这不是我想要的。我需要它像这样(ps照片):

背景纹理是全屏大小的深色照片

遮罩纹理为40像素大小。所以,我想在渲染时移动它以获得不同的形状。 主要代码:

CCSprite *textureSprite=[CCSprite spriteWithFile:@"bg_blank_alpha.png"];
CCSprite *maskSprite=[CCSprite spriteWithFile:@"bg_box_futher.png"];
CCRenderTexture * rt = [CCRenderTexture renderTextureWithWidth:textureSprite.contentSizeInPixels.width height:textureSprite.contentSizeInPixels.height];
textureSprite.position = ccp(textureSprite.contentSize.width/2, textureSprite.contentSize.height/2);
[maskSprite setBlendFunc:(ccBlendFunc){GL_SRC_COLOR, GL_ZERO}];
[textureSprite setBlendFunc:(ccBlendFunc){GL_ONE_MINUS_DST_ALPHA, GL_ZERO}];
[rt begin];
maskSprite.position=ccp(160, 240);
[maskSprite visit]; 
maskSprite.position=ccp(200, 240);
[maskSprite visit];       
[textureSprite visit];    
[rt end];

CCSprite *retval = [CCSprite spriteWithTexture:rt.sprite.texture];
retval.flipY = YES;
[self addChild:retval];
retval.position=ccp(160,240);

我不理解你所有的限制,但也许这会有所帮助

据我所知,问题发生在模糊区域重叠的地方。因此,应该避免模糊区域重叠。如果只想渲染精灵,则可以将单个精灵划分为不同的部分:

+-+----+-+ 
|a|  b |c|
+-+----+-+
| |    | |
|d|  e |f|
| |    | |
| |    | |
+-+----+-+ 
|g|  h |i|
+-+----+-+ 
然后仅在必要时渲染每个部分

+-+----+----+-+ 
|a|  b |  b |c|
+-+----+----+-+
| |    |    | |
|d|  e |  e |f|
| |    |    | |
| |    |    | |
+-+----+----+-+ 
|g|  h |  h |i|
+-+----+----+-+ 
希望这有意义并且有帮助。

你的意思是“九格”?这是一种方法。但它太复杂了。