我正在使用下面的代码来消除纹理。但我不知道如何检测划痕纹理的百分比..例如,当用户刮掉80%它应该淡出。任何人都可以帮我这个吗?
-(id) init
{
if( (self=[super init] ))
{
CGSize size = [[CCDirector sharedDirector] winSize];
[self setIsTouchEnabled:YES];
reset = YES;
bg = [CCSprite spriteWithFile:@"background.png"];
bg.position = ccp( size.width /2 , size.height/2 );
[self addChild:bg z:1];
burnSprite = [CCSprite spriteWithFile:@"fire.png"];
[burnSprite setBlendFunc:(ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }];
[burnSprite retain];
burnSprite.scale = 0.7f;
// Scratch Background
scratchBg = [[CCSprite spriteWithFile:@"scratchBg.png"] retain];
scratchBg.position = ccp(size.width / 2, size.height / 2);
// Scratch Layer
scratchLayer = [CCRenderTexture renderTextureWithWidth:size.width height:size.height];
scratchLayer.position = ccp(size.width / 2 , size.height / 2);
[[scratchLayer sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];
[self addChild:scratchLayer z:2];
[self schedule: @selector(tick:)];
}
return self;
}
- (void) drawTexture
{
// Update the render texture
[scratchLayer begin];
// Limit drawing to the alpha channel
glColorMask(0.0f, 0.0f, 0.0f, 1.0f);
// Draw
[burnSprite visit];
// Reset color mask
glColorMask(1.0f, 1.0f, 1.0f, 1.0f);
[scratchLayer end];
}
答案 0 :(得分:0)
这个问题出现在cocos2d-iphone论坛上。 http://www.cocos2d-iphone.org/forum/topic/12557
可以在此处找到解决问题的示例代码示例。 http://abitofcode.com/2012/04/ccrendertexture-category-percentage-complete/