"Scratch Off" effect (mask) CCRenderTexture + CCSprite instead of a solid color

Forums Programming cocos2d support (graphics engine) "Scratch Off" effect (mask) CCRenderTexture + CCSprite instead of a solid color

This topic contains 44 replies, has 22 voices, and was last updated by  gauravjalui 4 months, 4 weeks ago.

Viewing 25 posts - 1 through 25 (of 45 total)
Author Posts
Author Posts
January 13, 2011 at 1:46 am #227528

Col49
Participant
@col49

I’ve been trying to modify Steve Oldmeadow’s scratch off example so that the “scratch off” area is an image (CCSprite) instead of the color back. Steve used a CCRenderTexture and the fire image as a sprite to remove the alpha as you paint thus showing the background underneath.

Using the code bellow I was expecting to scratch away the scratchBg (yellow image) to see the background (purple image) bellow however I just see white for some reasons.

Here’s what I have:

Here’s what I get: result

Any help would be appreciated.

-(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];

//Set up the burn sprite that will "knock out" parts of the darkness layer depending on the
//alpha value of the pixels in the image.
burnSprite = [CCSprite spriteWithFile:@"fire.png"];
[burnSprite setBlendFunc: (ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }];
[burnSprite retain];

// Scratch Background
scratchBg = [[CCSprite spriteWithFile:@"scratchBackground.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);

[self addChild:scratchLayer z:2];

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

//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] >= 2) {
reset = YES;
} else {
CGPoint location = [touch locationInView: [touch view]];
burnSprite.position = CGPointMake(location.y, location.x);
}
}

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

-(void) tick: (ccTime) dt {

if (reset) {

[scratchLayer clear:0.0f g:0.0f b:0.0f a:1.0f];

[scratchLayer begin];

// Redraw scratch background
[scratchBg visit];

[scratchLayer end];

reset = NO;
}

// 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];
}

Cheers

Colin

January 13, 2011 at 7:21 pm #310236

Col49
Participant
@col49

Thanks to Andrea’s for sending me the solution. It turns out that I needed to adjust the glBlenFunc on the scratchLayer so it blended correctly with things underneath it. By default (as per 0.99.5) a CCRenderTexture sets the blend function on its sprite to {GL_ONE, GL_ONE_MINUS_SRC_ALPHA} which doesn’t produce the results I was hoping for.

What I really needed was:

// Scratch Layer
...
[[scratchLayer sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];

After doing this adjustment, I can now “scratch off” the scratchBg reviling the background (bg) underneath.

January 13, 2011 at 8:13 pm #310237

araker
Moderator
@araker

I proposed to change the blend function of the render texture sprite to get good results in cases with premultiplied alpha’s. Usually png’s are premultiplied, so I’m wondering why you are getting wrong results.

It could be that your sprites aren’t premultiplied (unlikely) or that for masking GL_SRC_ALPHA, .. is needed since the mask modifies the alpha value of the sprite beneath and when a premultiplied blend function is used (Gl_ONE, ..), that would also change the colors of the sprite beneath.

Long story short, could you check the value of opacityModifyRGB_ of your bg and scratchbg for me? That will tell me enough, so I can adjust the documentation accordingly.

Edit one other thing, the render texture also has a beginWithClear method (since 0.99.5), which is faster than calling clear and begin individually.

January 13, 2011 at 9:22 pm #310238

Col49
Participant
@col49

Thanks for taking an interest araker.

burnSprite opacityModifyRGB_ = 1

bg opacityModifyRGB_ = 0

scratchbg opacityModifyRGB_ = 0

I just made my testing images in Gimp and saved as PNG.

bg

scratchbg

Let me know if you need more info.

January 14, 2011 at 1:42 am #310239

araker
Moderator
@araker

Thanks for the info. The unlikely case seems to be it, which is a lot less unlikely if I’ve known this.

I’ll add a check to see if the target is the simulator and change the default blend function of the render texture sprite.

January 19, 2011 at 3:16 pm #310240

Col49
Participant
@col49

Hey Araker, I should point out that I ran into this problem in the simulator and on the device!

January 28, 2011 at 6:07 pm #310241

EvilRabbit
Participant
@evilrabbit

Great share guys. Made some changes to the location code:

CGPoint location = CCDirector sharedDirector] convertToGL:[touch locationInView: [touch view];

June 5, 2011 at 8:15 pm #310242

Mettich
Participant
@mettich

Hello,

first of all let me say thank u for this code. Still I need some things explained. First let me explain what i’m trying to do. I have a Mountain Sprite, which is a png. I want to alter this Sprite using this method. Obviously the png is irregular shaped and has transparent parts. Now my questions:

1. I don’t understand why the scratchBG is even displayed. It’s not added to the ScratchLayer and not added to the mainLayer.

2. I tried to use my mountain Sprite with this code. It’s getting displayed, but all transparent parts are black. The sprite and the black can be scratched off. Is there a way to leave the transparent parts transparent, so only the real sprite can be scratched off?

3. I’ve tried to convert the code to my app and got some issues using this code:

//Set up the burn sprite that will "knock out" parts of the darkness layer depending on the
//alpha value of the pixels in the image.
cutSprite = [CCSprite spriteWithFile:@"fire.png"];
[cutSprite setBlendFunc: (ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }];
[cutSprite retain];

// load mountain image
mountain=[[CCSprite spriteWithFile:@"mountain2.png"] retain];
mountain.position=ccp(mountain.contentSize.width/2+250,mountain.contentSize.height/2+13);
//[self addChild:mountain];

// Mountain Layer
mountainLayer = [CCRenderTexture renderTextureWithWidth:mountain.contentSize.width height:mountain.contentSize.height];
mountainLayer.position = ccp(mountain.contentSize.width/2+250,mountain.contentSize.height/2+13);
[[mountainLayer sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];
[self addChild:mountainLayer];

Then, in a collision handler i use:

// Test alter Mountain Sprite

cutSprite.position = ccp(280,50);

// Update the render texture
[mountainLayer begin];

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

// Draw
[cutSprite visit];

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

[mountainLayer end];

Well that doesn’t work. First, I don’t see my mountain any more. If i add the it to the mainLayer, i see it again, but it doesn’t get altered.

Can somebody please help me?

Thank in advance.

June 5, 2011 at 8:45 pm #310243

araker
Moderator
@araker

Is this your actual code, because the mountain won’t be visible since you haven’t visited the mountain sprite in a -begin -end.

In your init visit the mountain sprite to let it appear in the render texture. Also initialize the render texture with a transparent background, so the transparent parts will shine through.

[mountainLayer beginWithClear:0.f g:0.f b:0.f a:0.f];
[mountain visit];
[mountainLayer end];

I wouldn’t change the blend function of the render texture sprite, only change that when you’re having blending problems.

You’re also bound to run into positioning problems, for debugging try to save the content of the buffer to a png (using [mountainLayer saveBuffer:@"myfilename.jpg];) to see how the render texture actually looks like.

June 5, 2011 at 9:15 pm #310244

timTheMystic
@timthemystic

I’ve been tinkering with SuperSuRaccoon’s scratch-off code and combined the sample paint stroke code from RenderTextureTest.m and this may help you, thanks @SuperSuRaccoon:

//
// HelloWorldLayer.m
// ScratchOffDemo
//
// Created by SuperSu on 11-5-13.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//

// Import the interfaces
#import "HelloWorldScene.h"

// HelloWorld implementation
@implementation HelloWorld

+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
HelloWorld *layer = [HelloWorld node];

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

// return the scene
return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
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];

//Set up the burn sprite that will "knock out" parts of the darkness layer depending on the
//alpha value of the pixels in the image.
burnSprite = [CCSprite spriteWithFile:@"fire.png"];
[burnSprite setBlendFunc:(ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }];
[burnSprite retain];
burnSprite.scale = 0.7f;

//NSLog(@"burnSprite.width=%f ", [burnSprite boundingBox].size.width);

// 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)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] >= 2) {
reset = YES;
} else {
CGPoint location = [touch locationInView: [touch view]];
CGPoint curPosition = [[CCDirector sharedDirector] convertToGL:location];
burnSprite.position = CGPointMake(curPosition.x, curPosition.y);
_lastPosition = _currentPosition = burnSprite.position;
}
}

- (void)ccTouchesMoved:(NSSet*) touches withEvent:(UIEvent*) event {
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
CGPoint curPosition = [[CCDirector sharedDirector] convertToGL:location];
_currentPosition = CGPointMake(curPosition.x, curPosition.y);

// for extra points, we'll draw this smoothly from the last position and vary the sprite's
// scale/rotation/offset
float distance = ccpDistance(_lastPosition, _currentPosition);
if ( distance > 1 ) {
int d = (int)distance;
for (int i = 0; i < d; ++i) {

float difx = _currentPosition.x - _lastPosition.x;
float dify = _currentPosition.y - _lastPosition.y;
float delta = (float)i / distance;
[burnSprite setPosition:ccp(_lastPosition.x + (difx * delta), _lastPosition.y + (dify * delta))];
[burnSprite setRotation:rand() % 360];
float r = ((float)(rand() % 50) / 50.f) + 0.25f;
[burnSprite setScale:r];

[self drawTexture];
}
}

burnSprite.position = _currentPosition;

_lastPosition = _currentPosition;

} //

-(void) tick: (ccTime) dt {

if (reset) {

[scratchLayer clear:0.0f g:0.0f b:0.0f a:1.0f];

[scratchLayer begin];

// Redraw scratch background
[scratchBg visit];

[scratchLayer end];

reset = NO;
}

[self drawTexture];

}

- (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];

} //

// on "dealloc" 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't forget to call "super dealloc"
[super dealloc];

}

@end

June 6, 2011 at 8:27 pm #310245

Mettich
Participant
@mettich

Thanks guys. Works like a charm :)

Looking back, i guess i should have figured it out myself. Well, seems I wasn’t familiar with the visit concept. For everyone who is interested; in arakers code are some 0 missing. Here is what works for me:

[mountainLayer clear:0.0f g:0.0f b:0.0f a:0.0f];

July 9, 2011 at 6:59 am #310246

tsaintthomas
Participant
@tsaintthomas

Using this method, is there a way to detect when all of it is “scratched off”? I’ve been “scratching” my head about it but I’m thinking it would be difficult :)

July 9, 2011 at 6:56 pm #310247

araker
Moderator
@araker

After you visit the background the render texture, read out all pixel values using glReadPixels and save them in a array. When you want to test whether or not everything is scratched off, read the pixel values again and compare them to the saved values.

The render texture methods getUIImageFromBuffer and getUIImageAsDataFromBuffer show how to use glReadPixels.

March 23, 2012 at 10:38 pm #310248

Yohan85
Participant
@yohan85

Hi all,

I just tried this code which works perfectly.

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.

Is there an easy way to change something in the code aboce to have this effect ?

April 8, 2012 at 1:44 pm #310249

s.eropunov
@seropunov

Hi All sorry my English,

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.

April 10, 2012 at 12:48 pm #310250

dinabravo
Participant
@dinabravo

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?

April 29, 2012 at 11:09 pm #310251

abitofcode
Moderator
@abitofcode

@s.eropunov & @dinabravo Something along these lines added to your CCRenderTexture.m

-(float)getPercentageTransparent
{
NSAssert(pixelFormat_ == kCCTexture2DPixelFormat_RGBA8888,@"only RGBA8888 can be saved as image");

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(@"cocos2d: CCRenderTexture#getUIImageFromBuffer: not enough memory");
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 < ty; y++) {
// just want the last byte (alpha) for each pixel
for(x = 0; x < tx; x++) {
GLubyte alpha = buffer[(y * 4 * tx + ((x * 4)+3))];
if(alpha == 0) {
numberOfTransparent++;
}
}
}

free(buffer);

return (numberOfTransparent/numberOfPixels)*100;
}

April 30, 2012 at 11:33 am #310252

abitofcode
Moderator
@abitofcode

I’ve stuck up a sample project here -> http://abitofcode.com/2012/04/ccrendertexture-category-percentage-complete/

April 30, 2012 at 12:11 pm #310253

varedis
Moderator
@varedis

@abitofcode – 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

April 30, 2012 at 12:48 pm #310254

abitofcode
Moderator
@abitofcode

@varedis lol, it was one of those “I should be doing something else but that looks more interesting” type of problem :)

April 30, 2012 at 7:23 pm #310255

coldjacket
Participant
@coldjacket

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.

April 30, 2012 at 8:59 pm #310256

abitofcode
Moderator
@abitofcode

If it’s just your touch points that are off this may help http://bobueland.com/cocos2d/2011/the-magic-of-node-spaces/

April 30, 2012 at 9:16 pm #310257

coldjacket
Participant
@coldjacket

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.

April 30, 2012 at 9:45 pm #310258

coldjacket
Participant
@coldjacket
//
// HelloWorldLayer.m
// Scratch
//
// Created by Christopher Wilson on 29/04/2012.
// Copyright abitofcode ltd 2012. All rights reserved.
//

// Import the interfaces
#import "HelloWorldLayer.h"
#import "CCRenderTexture+Percentage.h"

// HelloWorldLayer implementation
@implementation HelloWorldLayer

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

// 'layer' 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:@"purpletracepart1.png"];
sourceImage.position = ccp( size.width * 0.5f , size.height * 0.5f );

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

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

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" 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:@"purpletracepart1completeglow.png"];

// 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:@"" fontName:@"ArialRoundedMTBold" fontSize:24];
[label setString:[NSString stringWithFormat:@"Percentage transparent: %.0f",[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 "knock out" parts of the darkness layer depending on the
//alpha value of the pixels in the image.
revealSprite = [CCSprite spriteWithFile:@"plexxusmode.png"];
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] >= 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:@"Percentage transparent: %.0f",[scratchableImage getPercentageTransparent]]];
}

// on "dealloc" 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't forget to call "super dealloc"
[super dealloc];
}
@end

April 30, 2012 at 10:32 pm #310259

abitofcode
Moderator
@abitofcode

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;

We’ll use the background image to determine where the nodespace we’re interested in is;

add the following to the .h file

#define BACK_IMAGE          5

and change this in the init method

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

In the ccTouchesBegan and ccTouchesMoved methods add

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] >= 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]; // <-- 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]; // <-- convert world location to node location
revealSprite.position = CGPointMake(location.x, location.y);
}

Viewing 25 posts - 1 through 25 (of 45 total)

You must be logged in to reply to this topic.