在這個cocos2d應用程序中,當我按下ccsprite時nslog不會觸發。有人能幫助我嗎?CGRect和touch
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
for (CCSprite *target in _targets) {
CGRect targetRect = CGRectMake(target.position.x - (target.contentSize.width/2),
target.position.y - (target.contentSize.height/2),
27,
40);
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
if (CGRectContainsPoint(targetRect, touchLocation)) {
NSLog(@"Moo cheese!");
}
}
return YES;
}
你試過打印出來的'targetRect 'if'前的''和'touchLocation'變量?他們是否正確?該方法是否開火? – Templar 2012-07-07 17:30:51
是否啓用觸摸屬性isTouchEnabled = YES; ? – zeiteisen 2012-07-07 20:17:40