2013-04-21 48 views
0

我使用Cocos2d 2.0和AWTextureFilter。我需要模糊紋理。這裏是我的代碼:Cocos2d 2.1 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

爲什麼會這樣?

回答

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]; 
+0

非常感謝,Steffen!有用。 – joycoma 2013-04-21 22:34:36