I have a custom subclass of CCSprite and in it I am doing this:
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];
during the sprite’s custom initialization.
Very interestingly, even when I do this later, from the main scene class that controls it:
[customSprite removeFromParentAndCleanup:YES];
The sprite still responds to this method, in its class:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
very curious indeed!
I did not initially have this, but I added it to the custom sprite class and it made no difference:
-(void)dealloc{
[super dealloc];
}
Any idea what is happening here?
UPDATE: not sure this is relevant but I’m wondering if removeFromParentAndCleanup works on a sprite that is added to sprite batch, as my sprite is indeed part of a CCSpriteBatchNode
CCTouchDispatcherwill retain your sprite. You need to call[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];when removing the sprite.