0

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

}
4

1 回答 1

0

这个问题已经出现在 cocos2d-iphone 论坛上。 http://www.cocos2d-iphone.org/forum/topic/12557

可以在此处找到用于解决您的问题的示例代码的一个很好的示例。 http://abitofcode.com/2012/04/ccrendertexture-category-percentage-complete/

于 2012-11-30T19:46:59.487 回答