我使用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
为什么?
我猜你必须将它与内容比例因子相乘,因为纹理内容的大小是以点为单位,而不是像素。
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];