我继承了一个名为 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");
}
}
}
但它不起作用,无法检测到精灵,那么错在哪里?请帮助我,谢谢