我繼承了一個名爲newSprite.h/newSprite.m精靈,我在它如何檢測子精靈觸摸
CCSprite *nsprite = [CCSprite spriteWithFile:@"mouse.png"];
[self addChild: nsprite];
和gamelayer.m,我添加以下代碼添加一個精靈
newSprite *newp = [newSprite node];
newp.position = ccp(actualX, actualY);
[self addChild:newp];
[_NSMutableArrayName addObject:newp];
,當我用下面的代碼來檢測我感動
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [self convertTouchToNodeSpace: touch];
for (CCSprite *target in _NSMutableArrayName) {
if (CGRectContainsPoint(target.boundingBox, location)) {
CCLOG(@"yes i am touched");
}
}
}
,但它不工作這精靈,精靈不能被檢測到,那麼錯在哪裏?請幫幫我,謝謝
它仍然不起作用 – yegomo
更新的代碼。試試看。你可能需要在'size'上應用'parentToNode'變換,但這應該是個訣竅。 –