Answer: Jonas
(Best answer)
In the layer containing sprites, you need to enter:
self.isTouchEnabled = YES;
Then, you can use the same event in the UIView, but the method they are called is different:
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
//in your touchesEnded event, you would want to see if you touched
//down and then up inside the same place, and do your logic there.
}
Answer: Terence
To achieve this effect, you can set a bounding box for the sprites. In the following code, I place all sprites in NSMutableArray and check whether they are within the bounding box. At the same time, make sure that the touch has been initialized. Operation:
You may need to adjust the x/y position to ensure the "center position" of the sprite.
Answer: John
David's code will cause error messages on Cocos 0.7.3 and 2.2.1, so I used CGRectMake instead of CGMakeRect and used [touch locationInView:touch.view] to correct the [touch location] error:
Answer: Jonas
(Best answer)
In the layer containing sprites, you need to enter:
Then, you can use the same event in the UIView, but the method they are called is different:
Answer: Terence
To achieve this effect, you can set a bounding box for the sprites. In the following code, I place all sprites in NSMutableArray and check whether they are within the bounding box. At the same time, make sure that the touch has been initialized. Operation:
Answer: David Higgins
Based on Jonas's answer, I made further improvements:
You may need to adjust the x/y position to ensure the "center position" of the sprite.
Answer: John
David's code will cause error messages on Cocos 0.7.3 and 2.2.1, so I used CGRectMake instead of CGMakeRect and used [touch locationInView:touch.view] to correct the [touch location] error: