I have tried several ways and search solutions for a while. Finally I figure it out the right fix for this issue. The key is to make sure the container(CCLayer) does not swallow all the touch events(so sprites inside of it can still receive the touch event if itself is touched). Priority does not seem to matter. However, I still make sure that the parent has lower priority than its children.
Here is the code and diagram showing the correct solution. The subclass of CCSprite will be able to receive touch events via the following three delegate methods by setting the right CCTouchDispatcher parameters.
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
Relationship between CCLayer and CCSprite and their configurations.
If there are more than one sprite, and all of them need to check if they are touched or not, then make sure you change the swallowsTouches parameter to be "NO". So after the first child of the CCLayer receives the touch event, it will continue to pass to other children(sprites).
0 comments:
Post a Comment