我正在使用下面的代码来刮掉纹理。但我不确定如何检测划伤纹理的百分比。例如,当用户划伤 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];
}