Hi guys
Im trying out something.
I have 4 sprites in 2x2.
When i touch the one of the sprite, the touched sprite will disappears.
But im having problem on the code. when it touch the any first sprite it dissappers. when i touch the any second sprite it crashes.
here is the error;
[handler.delegate performSelector:helper.touchesSel withObject:mutableTouches withObject:event];
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {
self.isTouchEnabled = YES;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"coordinates.plist"];
CCSpriteBatchNode *randomsprites = [CCSpriteBatchNode batchNodeWithFile:@"coordinates.png"];
[self addChild:randomsprites];
white = [CCSprite spriteWithSpriteFrameName:@"Wh_White.png"];
white.position=ccp(50,50);
[self addChild:white];
yellow = [CCSprite spriteWithSpriteFrameName:@"Ye_Yellow.png"];
yellow.position=ccp(50,150);
[self addChild:yellow];
blue = [CCSprite spriteWithSpriteFrameName:@"Bl_Blue.png"];
blue.position=ccp(250,50);
[self addChild:blue];
green = [CCSprite spriteWithSpriteFrameName:@"Gr_Green.png"];
green.position=ccp(250,150);
[self addChild:green];
}
return self;
}
-(void) fadeBlue
{
[self removeChild:blue cleanup:YES];
}
-(void) fadeGreen
{
[self removeChild:green cleanup:YES];
}
-(void) fadeWhite
{
[self removeChild:white cleanup:YES];
}
-(void) fadeYellow
{
[self removeChild:yellow cleanup:YES];
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView: [myTouch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
CGRect yellowSprite = CGRectMake(yellow.position.x - (yellow.contentSize.width/2),
yellow.position.y - (yellow.contentSize.height/2),
yellow.contentSize.width,
yellow.contentSize.height);
if (CGRectContainsPoint(yellowSprite, location)) {
[self fadeYellow];
NSLog(@"yellow");
}
CGRect blueSprite = CGRectMake(blue.position.x - (blue.contentSize.width/2),
blue.position.y - (blue.contentSize.height/2),
blue.contentSize.width,
blue.contentSize.height);
if (CGRectContainsPoint(blueSprite, location)) {
[self fadeBlue];
NSLog(@"Blue");
}
CGRect greenSprite = CGRectMake(green.position.x - (green.contentSize.width/2),
green.position.y - (green.contentSize.height/2),
green.contentSize.width,
green.contentSize.height);
if (CGRectContainsPoint(greenSprite, location)) {
[self fadeGreen];
NSLog(@"green");
}
CGRect whiteSprite = CGRectMake(white.position.x - (white.contentSize.width/2),
white.position.y - (white.contentSize.height/2),
white.contentSize.width,
white.contentSize.height);
if (CGRectContainsPoint(whiteSprite, location)) {
[self fadeWhite];
NSLog(@"white");
}
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// don't forget to call "super dealloc"
[super dealloc];
}
@end
Is my coding wrong? is there another way to do it.