<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Topic: &quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/12557</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Thu, 23 May 2013 15:01:37 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/topic/12557" rel="self" type="application/rss+xml" />

		<item>
			<title>wiralim on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-204709</link>
			<pubDate>Sat, 27 Oct 2012 14:56:50 +0000</pubDate>
			<dc:creator>wiralim</dc:creator>
			<guid isPermaLink="false">204709@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello all, sorry for my English is not good.<br />
how do I let the user resolve 50 percent of the scratch image without releasing his finger and without laggy of the phone ?
</p></description>
		</item>
		<item>
			<title>unrealaz on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-180609</link>
			<pubDate>Wed, 12 Sep 2012 15:50:59 +0000</pubDate>
			<dc:creator>unrealaz</dc:creator>
			<guid isPermaLink="false">180609@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>If anyone needs to use abitofcode getpercentage function but with a rectangle: (To check if only a part of the texture was scratched off)</p>
<pre><code>//
//  CCRenderTexture+Percentage.m
//  Digger
//
//  Created by on 12/09/2012.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCRenderTexture.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCRenderTexture+Percentage.h&#34;

@implementation CCRenderTexture (Percentage)

-(float) getPercentageTransparent :(CGRect) rect
{
    NSAssert(pixelFormat_ == kCCTexture2DPixelFormat_RGBA8888,@&#34;only RGBA8888 can be saved as image&#34;);

    int tx = rect.origin.x + rect.size.width;
    int ty = rect.origin.y + rect.size.height;

    int bitsPerPixel                = 4 * 8;
    int bytesPerPixel               = bitsPerPixel / 8;
    int bytesPerRow                 = bytesPerPixel * (tx - rect.origin.x);
    NSInteger myDataLength          = bytesPerRow * (ty - rect.origin.y);

    int numberOfPixels              = (tx - rect.origin.x) * (ty - rect.origin.y);
    float numberOfTransparent       = 0;

    GLubyte *buffer = malloc(sizeof(GLubyte)*myDataLength);

    if( ! (buffer) )
	{
        CCLOG(@&#34;cocos2d: CCRenderTexture#<a href='http://www.cocos2d-iphone.org/forum/tags/getuiimagefrombuffer'>getUIImageFromBuffer</a>: not enough memory&#34;);
        free(buffer);
        return -1.0f;
    }

    [self begin];
    glReadPixels(rect.origin.x,rect.origin.y,(tx - rect.origin.x),(ty - rect.origin.y),GL_RGBA,GL_UNSIGNED_BYTE, buffer);
    [self end];

    int x,y;
    for(y = 0; y &#60; (ty - rect.origin.y); y++)
	{
        // just want the last byte (alpha) for each pixel
        for(x = 0; x &#60; (tx - rect.origin.x); x++)
		{
            GLubyte alpha = buffer[(y * 4 * (int)(tx - rect.origin.x) + ((x * 4) + 3))];
            if(alpha == 0)
			{
                numberOfTransparent++;
            }
        }
    }    

    free(buffer);

    return (numberOfTransparent/numberOfPixels)*100;
}
@end</code></pre></description>
		</item>
		<item>
			<title>mayoxy on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-165662</link>
			<pubDate>Fri, 22 Jun 2012 21:21:17 +0000</pubDate>
			<dc:creator>mayoxy</dc:creator>
			<guid isPermaLink="false">165662@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi, </p>
<p>can someone help me with ccBlendFunc ? because i have background image classic png with no transparency but higher image, which is scratched off is png with a few places with transparency. especialy edges. so ccBlendFunc\s from this thread are not good enough :/<br />
can some help me ?<br />
thanks
</p></description>
		</item>
		<item>
			<title>nikhil.dhamsaniya on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-165465</link>
			<pubDate>Thu, 21 Jun 2012 13:49:14 +0000</pubDate>
			<dc:creator>nikhil.dhamsaniya</dc:creator>
			<guid isPermaLink="false">165465@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Can we have scratch in as scratch off?<br />
Sorry for bad english.<br />
Pls check the video.<br />
Can any body have idea draw on charactor with white color can be done by masking?<br />
or is it the right way,<br />
is there any other idea we can work upon for to implement drawing on charactor "a" using cocos2d?<br />
Help is greatly appreciated.</p>
<p><object></p>
<param name="movie" value="http://www.youtube.com/v/JI__fbKJVLI?version=3&#38;feature=player_detailpage" />
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" /><embed src="http://www.youtube.com/v/JI__fbKJVLI?version=3&#38;feature=player_detailpage" type="application/x-shockwave-flash" width="640" height="360" /></object>
</p></description>
		</item>
		<item>
			<title>Yohan85 on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-164266</link>
			<pubDate>Wed, 13 Jun 2012 15:39:46 +0000</pubDate>
			<dc:creator>Yohan85</dc:creator>
			<guid isPermaLink="false">164266@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>+1
</p></description>
		</item>
		<item>
			<title>ksjogo on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-164265</link>
			<pubDate>Wed, 13 Jun 2012 15:38:38 +0000</pubDate>
			<dc:creator>ksjogo</dc:creator>
			<guid isPermaLink="false">164265@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I made the fragment shader way for a job, so I am unsure if I am allowed to share it for free.<br />
But if you have any questions, just ask.
</p></description>
		</item>
		<item>
			<title>ibawt on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-164248</link>
			<pubDate>Wed, 13 Jun 2012 14:21:38 +0000</pubDate>
			<dc:creator>ibawt</dc:creator>
			<guid isPermaLink="false">164248@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'd love to see the fragment shader version.
</p></description>
		</item>
		<item>
			<title>mayoxy on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-164150</link>
			<pubDate>Tue, 12 Jun 2012 21:28:55 +0000</pubDate>
			<dc:creator>mayoxy</dc:creator>
			<guid isPermaLink="false">164150@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>do you know how to change it ?
</p></description>
		</item>
		<item>
			<title>mayoxy on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-163973</link>
			<pubDate>Mon, 11 Jun 2012 20:29:11 +0000</pubDate>
			<dc:creator>mayoxy</dc:creator>
			<guid isPermaLink="false">163973@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>thank you abitofcode :)</p>
<p>and what if i programing it for ipad and i do not want use images in whole size of ipad. i want use one image size of 400x400 and second for example the same 400x400 size.  if i use your method for get percentage i need to scratch off whole screen of ipad, but i want to scratch off only 400x400 the picture for scratch. because the problem is that , when i scratch off whole image 400x400 the function get percentace get me only 25%, what is 25 % of ipad screen, but in my opinion it would be 100%. not just only 25%.  hm . i dont know if i explaining right. hm. do you understand ? </p>
<p>thank you
</p></description>
		</item>
		<item>
			<title>abitofcode on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-163711</link>
			<pubDate>Sun, 10 Jun 2012 23:00:43 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">163711@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/43584'>mayoxy</a> Check out this post <a href="http://www.cocos2d-iphone.org/forum/topic/12557#post-156306" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/12557#post-156306</a> </p>
<p>Careful of the recursion when you get to the end of the post ;)
</p></description>
		</item>
		<item>
			<title>mayoxy on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-163698</link>
			<pubDate>Sun, 10 Jun 2012 20:33:42 +0000</pubDate>
			<dc:creator>mayoxy</dc:creator>
			<guid isPermaLink="false">163698@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>how did you check how much percent of picture is scratch already? i see on the video that at the finish the label is showen that is scrach. how did you checking how many for example percentage is already scratched?
</p></description>
		</item>
		<item>
			<title>acorbi on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-162929</link>
			<pubDate>Tue, 05 Jun 2012 21:22:46 +0000</pubDate>
			<dc:creator>acorbi</dc:creator>
			<guid isPermaLink="false">162929@http://www.cocos2d-iphone.org/forum/</guid>
			<description><blockquote><p>i'm not nearly as good at opengl as the people who make these posts but I am good at doing hacks to get what I want. What I would do is just make multiple scratch offs then just switch in code when you want. but maybe others have a better solution.</p></blockquote>
<p>Yeah i though also about that option but this has to happen continuosly, meaning that all of the layers (in my case 4) should co-exist at the same time.</p>
<blockquote><p>For having multiple burn layer I would recommend a custom vertex shader, firstly you mix the base with overlay 1 using alpha from rendertexture 1, then you mix this result with overlay 2 using alpha from rendertexture 2.</p></blockquote>
<p>That sounds more suitable for my purpose but also more complicated. The best thing for me would be to generate a new Sprite with the combination of 2 Layers everytime touchEnded gets call, the workflow would be like this:</p>
<p>-&#62; touchMoved  erases part of the top layer -&#62; touchEnded -&#62; top layer and layer below get combined on a new Sprite. -&#62; start again</p>
<p>What do you think about this approach? Could be reasonable and performant? Any code hints? I will try it tomorrow and come back to you here to share the infos.
</p></description>
		</item>
		<item>
			<title>ksjogo on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557/page/2#post-162926</link>
			<pubDate>Tue, 05 Jun 2012 20:52:49 +0000</pubDate>
			<dc:creator>ksjogo</dc:creator>
			<guid isPermaLink="false">162926@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a version running with gles20 and a special frag shader: <a href="http://www.youtube.com/watch?v=MWfihxUm-Q4" rel="nofollow">http://www.youtube.com/watch?v=MWfihxUm-Q4</a></p>
<p>For burning slowly, why dont you just paint into the render texture automatically?</p>
<p>For having multiple burn layer I would recommend a custom vertex shader, firstly you mix the base with overlay 1 using alpha from rendertexture 1, then you mix this result with overlay 2 using alpha from rendertexture 2.</p>
<p>Then you only need to check which rendertexture to use when painting - easy solution would be two custom utilities, otherwise you needed some alphachecking for each pixel.
</p></description>
		</item>
		<item>
			<title>coldjacket on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-162924</link>
			<pubDate>Tue, 05 Jun 2012 20:46:38 +0000</pubDate>
			<dc:creator>coldjacket</dc:creator>
			<guid isPermaLink="false">162924@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>i'm not nearly as good at opengl as the people who make these posts but I am good at doing hacks to get what I want. What I would do is just make multiple scratch offs then just switch in code when you want. but maybe others have a better solution
</p></description>
		</item>
		<item>
			<title>acorbi on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-162912</link>
			<pubDate>Tue, 05 Jun 2012 18:14:18 +0000</pubDate>
			<dc:creator>acorbi</dc:creator>
			<guid isPermaLink="false">162912@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi There!</p>
<p>First of all say that this post is great and have helped me a lot.</p>
<p>But now i am bringing a new challenge to the scenario... How about having multiple layers? Say you scratch the first layer so you see the one just underneath, now you tap on the one that was revealed and scratch it as well....</p>
<p>Do you have any hints about which considerations to take?
</p></description>
		</item>
		<item>
			<title>fringley on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-160797</link>
			<pubDate>Tue, 22 May 2012 12:04:13 +0000</pubDate>
			<dc:creator>fringley</dc:creator>
			<guid isPermaLink="false">160797@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hmm, seems that this was possible - I wasn't updating the texture properly.  To my next problem - I've been trying to "slowly" reveal the image underneath, by say, burning into the alpha channel a little at a time.  I've tried this by modifying the glColorMask, but unless the alpha value is 1, it doesn't work.</p>
<p><code><br />
    // Limit drawing to the alpha channel<br />
    glColorMask(0.0f, 0.0f, 0.0f, variableAlpha);<br />
</code>
</p></description>
		</item>
		<item>
			<title>fringley on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-160784</link>
			<pubDate>Tue, 22 May 2012 11:06:39 +0000</pubDate>
			<dc:creator>fringley</dc:creator>
			<guid isPermaLink="false">160784@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Has anyone achieved this using gles20 yet?  My knowledge of OpenGL is pretty ropey at best and it doesn't seem like it should be too complicated!  Any pointers would be gratefully received.
</p></description>
		</item>
		<item>
			<title>coldjacket on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156514</link>
			<pubDate>Mon, 30 Apr 2012 23:44:05 +0000</pubDate>
			<dc:creator>coldjacket</dc:creator>
			<guid isPermaLink="false">156514@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>woohoo. thanx mate. I get it now when I made your changes and also I understood that I needed to change my source image position and my rendertexture position. thanks again for the class and for the help.
</p></description>
		</item>
		<item>
			<title>abitofcode on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156510</link>
			<pubDate>Mon, 30 Apr 2012 22:32:37 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">156510@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Your touchpoint is off, the video should clear it up. As you have moved the node the touch location in the world space needs converting to a location in the nodespace;</p>
<p>We'll use the background image to determine where the nodespace we're interested in is;<br />
add  the following to the .h file<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> BACK_IMAGE          5</code></pre>
<p>and change this in the init method<br />
<pre><code>// add the label as a child to this Layer
    [self addChild: back z:0 tag:BACK_IMAGE];</code></pre>
<p>In the ccTouchesBegan and ccTouchesMoved methods add</p>
<pre><code>- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch *touch = [touches anyObject];
	if ([touch tapCount] &#62;= 3) {
        [self reset];
	} else {
        CCRenderTexture *backImage = (CCRenderTexture*)[self getChildByTag:BACK_IMAGE]; 

		CGPoint location = [touch locationInView: [touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];
        location = [backImage convertToNodeSpace:location];        // &#60;-- convert world location to node location
        revealSprite.position = CGPointMake(location.x, location.y);
	}
}

//Move the burn sprite
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    CCRenderTexture *backImage = (CCRenderTexture*)[self getChildByTag:BACK_IMAGE];    

	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    location = [backImage convertToNodeSpace:location];       // &#60;-- convert world location to node location
	revealSprite.position = CGPointMake(location.x, location.y);
}</code></pre></description>
		</item>
		<item>
			<title>coldjacket on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156505</link>
			<pubDate>Mon, 30 Apr 2012 21:45:07 +0000</pubDate>
			<dc:creator>coldjacket</dc:creator>
			<guid isPermaLink="false">156505@http://www.cocos2d-iphone.org/forum/</guid>
			<description><pre><code>//
//  HelloWorldLayer.m
//  Scratch
//
//  Created by Christopher Wilson on 29/04/2012.
//  Copyright abitofcode ltd 2012. All rights reserved.
//

// Import the interfaces
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;HelloWorldLayer.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCRenderTexture+Percentage.h&#34;

// HelloWorldLayer implementation
@implementation HelloWorldLayer

+(CCScene *) scene
{
	// &#039;scene&#039; is an autorelease object.
	CCScene *scene = [CCScene node];

	// &#039;layer&#039; is an autorelease object.
	HelloWorldLayer *layer = [HelloWorldLayer node];

	// add layer as a child to scene
	[scene addChild: layer];

	// return the scene
	return scene;
}

-(void)reset
{
    // ask director the the window size
    CGSize size = [[CCDirector sharedDirector] winSize];

    CCRenderTexture *scratchableImage = (CCRenderTexture*)[self getChildByTag:SCRATCHABLE_IMAGE];    

    CCSprite *sourceImage = [CCSprite spriteWithFile:@&#34;purpletracepart1.png&#34;];
    sourceImage.position = ccp( size.width * 0.5f , size.height * 0.5f );

    [scratchableImage begin];
    [sourceImage visit];
    [scratchableImage end];

   // NSLog(@&#34;Transparent: %f percent&#34;,[scratchableImage getPercentageTransparent]);
}

// on &#34;init&#34; you need to initialize your instance
-(id) init
{
	// always call &#34;super&#34; init
	// Apple recommends to re-assign &#34;self&#34; with the &#34;super&#34; return value
	if( (self=[super init])) {

        positionbottomsquare = ccp(477/2, 320 - 415/2);

		// ask director the the window size
		CGSize size = [[CCDirector sharedDirector] winSize];

		// Create a background image
        CCSprite *back = [CCSprite spriteWithFile:@&#34;purpletracepart1completeglow.png&#34;];

        // position the label on the center of the screen
		back.position =  ccp( size.width * 0.5f , size.height * 0.5f );
		back.position = positionbottomsquare;

		// add the label as a child to this Layer
		[self addChild: back];

        // Scratchable layer
        CCRenderTexture *scratchableImage = [CCRenderTexture renderTextureWithWidth:size.width height:size.height];
       // CCRenderTexture *scratchableImage = [CCRenderTexture renderTextureWithWidth:back.contentSize.width height:back.contentSize.height];
        scratchableImage.position = ccp( size.width * 0.5f , size.height * 0.5f );
        scratchableImage.position = positionbottomsquare;
        [self addChild:scratchableImage z:1 tag:SCRATCHABLE_IMAGE];
        [[scratchableImage sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];

        // Source image
        [self reset];

        /*
		// create and initialize a Label
		CCLabelTTF *label = [CCLabelTTF labelWithString:@&#34;&#34; fontName:@&#34;ArialRoundedMTBold&#34; fontSize:24];
        [label setString:[NSString stringWithFormat:@&#34;Percentage transparent: %.0f&#34;,[scratchableImage getPercentageTransparent]]];
        [label setColor:ccc3(0,0,0)];
		label.position =  ccp( size.width /2 , size.height - label.contentSize.height );
        [self addChild:label z:2 tag:LABEL_TEXT];
        */

		//Set up the burn sprite that will &#34;knock out&#34; parts of the darkness layer depending on the
		//alpha value of the pixels in the image.
		revealSprite = [CCSprite spriteWithFile:@&#34;plexxusmode.png&#34;];
        revealSprite.position = ccp( -10000, 0);
		[revealSprite setBlendFunc: (ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }];
		[revealSprite retain];   

        [self schedule: @selector(tick:)];  

        self.isTouchEnabled = YES;
	}
	return self;
}

-(void) tick: (ccTime) dt
{
    CCRenderTexture *scratchableImage = (CCRenderTexture*)[self getChildByTag:SCRATCHABLE_IMAGE];

    // Update the render texture
    [scratchableImage begin];

    // Limit drawing to the alpha channel
    glColorMask(0.0f, 0.0f, 0.0f, 1.0f);

    // Draw
    [revealSprite visit];

    // Reset color mask
    glColorMask(1.0f, 1.0f, 1.0f, 1.0f);

    [scratchableImage end];
}

//Move the burn sprite unless user double taps - then we reset the darkness layer
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch *touch = [touches anyObject];
	if ([touch tapCount] &#62;= 3) {
        [self reset];
	} else {
		CGPoint location = [touch locationInView: [touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];
		revealSprite.position = CGPointMake(location.x, location.y);
	}
}

//Move the burn sprite
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
	revealSprite.position = CGPointMake(location.x, location.y);
}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    revealSprite.position = ccp( -10000, 0);    

   // CCRenderTexture *scratchableImage = (CCRenderTexture*)[self getChildByTag:SCRATCHABLE_IMAGE];
   // CCLabelTTF *label = (CCLabelTTF*) [self getChildByTag:LABEL_TEXT];
   // [label setString:[NSString stringWithFormat:@&#34;Percentage transparent: %.0f&#34;,[scratchableImage getPercentageTransparent]]];
}

// on &#34;dealloc&#34; you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)

	// don&#039;t forget to call &#34;super dealloc&#34;
	[super dealloc];
}
@end</code></pre></description>
		</item>
		<item>
			<title>coldjacket on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156500</link>
			<pubDate>Mon, 30 Apr 2012 21:16:55 +0000</pubDate>
			<dc:creator>coldjacket</dc:creator>
			<guid isPermaLink="false">156500@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>sorry. i didn't mean my touchpoint is off. i know my touch point is right because i have another sprite going to the correct touch point. the scratch point is off from the the touchpoint. just for testing though i basically took ur example and changed the back and source sprite and changed the position of the back sprite and the ccrendertexutre and the scratch is off.
</p></description>
		</item>
		<item>
			<title>abitofcode on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156498</link>
			<pubDate>Mon, 30 Apr 2012 20:59:07 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">156498@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>If it's just your touch points that are off this may help <a href="http://bobueland.com/cocos2d/2011/the-magic-of-node-spaces/" rel="nofollow">http://bobueland.com/cocos2d/2011/the-magic-of-node-spaces/</a>
</p></description>
		</item>
		<item>
			<title>coldjacket on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156487</link>
			<pubDate>Mon, 30 Apr 2012 19:23:42 +0000</pubDate>
			<dc:creator>coldjacket</dc:creator>
			<guid isPermaLink="false">156487@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>thank you so much for this! i'm just having a little problem setting it up with a back and source image that are not the same size as your sample and not positioned in the screen center. any advice. Mine seems to work except the scratch points are off. The closest I got was by only changing the back image position and the ccrenduretexture position. so I'm trying to setup a different non full window sized back and source image at another position not as the screen center.
</p></description>
		</item>
		<item>
			<title>abitofcode on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156407</link>
			<pubDate>Mon, 30 Apr 2012 12:48:38 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">156407@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/20492'>varedis</a> lol, it was one of those "I should be doing something else but that looks more interesting" type of problem :)
</p></description>
		</item>
		<item>
			<title>varedis on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156396</link>
			<pubDate>Mon, 30 Apr 2012 12:11:55 +0000</pubDate>
			<dc:creator>varedis</dc:creator>
			<guid isPermaLink="false">156396@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/1222'>abitofcode</a> - I can't believe you beat me to the punch. I was trying to come up with this method just a few days ago, nice work
</p></description>
		</item>
		<item>
			<title>abitofcode on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156385</link>
			<pubDate>Mon, 30 Apr 2012 11:33:40 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">156385@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've stuck up a sample project here -&#62; <a href="http://abitofcode.com/2012/04/ccrendertexture-category-percentage-complete/" rel="nofollow">http://abitofcode.com/2012/04/ccrendertexture-category-percentage-complete/</a></p>
<p><img src="http://abitofcode.com/download/cocos2d/scratch.jpg" />
</p></description>
		</item>
		<item>
			<title>abitofcode on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-156306</link>
			<pubDate>Sun, 29 Apr 2012 23:09:20 +0000</pubDate>
			<dc:creator>abitofcode</dc:creator>
			<guid isPermaLink="false">156306@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/10160'>s</a>.eropunov &#38; @<a href='http://www.cocos2d-iphone.org/forum/profile/80417'>dinabravo</a> Something along these lines added to your CCRenderTexture.m</p>
<pre><code>-(float)getPercentageTransparent
{
    NSAssert(pixelFormat_ == kCCTexture2DPixelFormat_RGBA8888,@&#34;only RGBA8888 can be saved as image&#34;);

	CGSize s = [texture_ contentSizeInPixels];
	int tx = s.width;
	int ty = s.height;

	int bitsPerComponent			= 8;
    int bitsPerPixel                = 4 * 8;
    int bytesPerPixel               = bitsPerPixel / 8;
	int bytesPerRow					= bytesPerPixel * tx;
	NSInteger myDataLength			= bytesPerRow * ty;

    int numberOfPixels              = tx * ty;
    float numberOfTransparent       = 0;

	GLubyte *buffer	= malloc(sizeof(GLubyte)*myDataLength);

	if( ! (buffer) ) {
		CCLOG(@&#34;cocos2d: CCRenderTexture#<a href='http://www.cocos2d-iphone.org/forum/tags/getuiimagefrombuffer'>getUIImageFromBuffer</a>: not enough memory&#34;);
        free(buffer);
		return -1.0f;
	}

	[self begin];
        glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, buffer);
	[self end];

    int x,y;
	for(y = 0; y &#60; ty; y++) {
        // just want the last byte (alpha) for each pixel
		for(x = 0; x &#60; tx; x++) {
            GLubyte alpha = buffer[(y * 4 * tx + ((x * 4)+3))];
            if(alpha == 0) {
                numberOfTransparent++;
            }
		}
	}    

    free(buffer);

    return (numberOfTransparent/numberOfPixels)*100;
}</code></pre></description>
		</item>
		<item>
			<title>dinabravo on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-152671</link>
			<pubDate>Tue, 10 Apr 2012 12:48:59 +0000</pubDate>
			<dc:creator>dinabravo</dc:creator>
			<guid isPermaLink="false">152671@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I have the same problem as eropunov, I would like to know how to test if the image is scratched (at least 80% of it). getUIImageAsDataFromBuffer is not available anymore so I don't know how to read the render texture from a buffer.. Can anyone help with this?
</p></description>
		</item>
		<item>
			<title>s.eropunov on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-152368</link>
			<pubDate>Sun, 08 Apr 2012 13:44:05 +0000</pubDate>
			<dc:creator>s.eropunov</dc:creator>
			<guid isPermaLink="false">152368@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi All sorry my English,<br />
In me the question as it is possible to determine that I did rub over entire surface? In order to determine to make a logical end of the game.
</p></description>
		</item>
		<item>
			<title>Yohan85 on "&quot;Scratch Off&quot; effect (mask) CCRenderTexture + CCSprite instead of a solid color"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12557#post-149911</link>
			<pubDate>Fri, 23 Mar 2012 22:38:32 +0000</pubDate>
			<dc:creator>Yohan85</dc:creator>
			<guid isPermaLink="false">149911@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all,</p>
<p>I just tried this code which works perfectly.</p>
<p>There is an option I'd like to change, but can't find what parameters is responsible for that : so far, each time I touch the screen, the sprite is created on the screen to reveal the background. What I'd like is that the alpha of the sprite would be half (or more) lower, so that I'd need to "scratch" twice my screen in order to have the background revealed.</p>
<p>Is there an easy way to change something in the code aboce to have this effect ?
</p></description>
		</item>

	</channel>
</rss>
