Hi,
I've got a Problem with a CCSprite subclass with the CCTargetedTouchDelegate Protocol.
The problem is that the first CCSprite gets the touch correct, but all following touches are claimed by
the first touched CCSprite, even if I touch somewhere else, where nothing should happen.
Here is the touch part of my implementation in the subclassed CCSprite:
- (void)onEnter
{
if (self.touchable) {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
[super onEnter];
}
- (CGRect)rect
{
CGSize s = [self.texture contentSize];
return CGRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
}
- (BOOL)containsTouchLocation:(UITouch *)touch
{
return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]);
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
//check if vehicle is on screen -> if not return NO
if (self.currentLane == IZLaneOutOfScreen) return NO;
if ( ![self containsTouchLocation:touch] ) return NO;
if (self.touchable) {
[self stopAllActions];
NSLog(@"I GOT TOUCHED!, myPosition: x: %d y: %d",self.position.x , self.position.y);
}
return self.touchable;
}
What could be wrong?
I do everything like the pong example in the test folder of cocos2d