self.isTouchEnabled = YES;
2. 然後一樣在 CCLayer 加入這一段
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
UITouch* touch = [touches anyObject];
//先取得touch 的坐標 CGPoint location = [touch locationInView:[touch view]];location = [[CCDirector sharedDirector] convertToGL:location];
//驗證坐標CCSprite *m_targetSprite = xxx; <==取得目標物件 if (CGRectContainsPoint(m_targetSprite.boundingBox, location)) {//touch.....}}
附註: 有時CCLayer 的坐標也要考慮進去才行~~~
沒有留言:
張貼留言