Search code examples
objective-ccocos2d-iphoneccspritexcode

cocos2d sprites disable touches


i haves game with cocos2d i have many sprites i'm using touch to sprite with this

CGRectContainsPoint([[gameImages objectAtIndex:i] boundingBox], location)
CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL: location];

but when i touched the sprite must be deleted i have

[self removeChild:[gameImages objectAtIndex:bacvacIndexner[0]] cleanup:YES];

but the touch works because i use the object coordinates and i cant delete object when i removin that from child what can i do?why i can get the touch event for sprite . are anything without coordinate method?


Solution

  • Use a callback so a higher class remove the object. Inside your to-be-removed class:

    [self.touchDelegate performSelector:@selector(removeMe:) withObject:self afterDelay:0.0f];