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");
}
}
}
しかし、それは動作しません、スプライトが検出されないので、どこが間違っていますか? 助けてください、ありがとう