Cocos2d 2.1 AWTextureFilter仅模糊部分纹理

时间:2013-04-21 04:30:00

标签: cocos2d-iphone blur

我使用Cocos2d 2.0和AWTextureFilter。我需要模糊纹理。这是我的代码:

//Create mutable texture
CCTexture2DMutable *texture = [[CCTexture2DMutable alloc] initWithCGImage:[UIImage imageNamed:@"image.png"].CGImage resolutionType:kCCResolutionUnknown];

//Apply blur to the mutable texture
[AWTextureFilter blur:texture radius:10 rect:CGRectMake(0, 0, texture.contentSize.width, texture.contentSize.height)];

//Create sprites to show the textures
CCSprite *sprite = [CCSprite spriteWithTexture:texture];
sprite.position = ccp(winSize.width/2, winSize.height/2);
[layer addChild:sprite];

但是结果我得到精灵只有部分模糊(截图): http://img62.imageshack.us/img62/182/blura.png

为什么会这样?

1 个答案:

答案 0 :(得分:0)

我猜你必须用内容比例因子对其进行多次处理,因为纹理内容大小是以点为单位,而不是像素。

CGSize size = texture.contentSize;
CGRect rect = CGRectMake(0, 0, 
                         size.width * CC_CONTENT_SCALE_FACTOR(), 
                         size.height * CC_CONTENT_SCALE_FACTOR());
[AWTextureFilter blur:texture radius:10 rect:rect];