0

我使用 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

为什么这样?

4

1 回答 1

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];
于 2013-04-21T14:23:54.897 回答