我需要帮助你试图删除一个不断在不同位置重生的ccnode,并将它们添加到一个数组中以控制屏幕上的精灵,但事实是我无法删除它们,它检测到接触但没有删除任何想法?这是我用来获取节点的代码。提前致谢。
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToUI:location];
for (CCNode *sprite in _spritesOnScreen) {
if (CGPointEqualToPoint(sprite.position, location)) {
[_spritesOnScreen removeObject:sprite];
[self removeChild:sprite cleanup:YES];
}
}
}
答案 0 :(得分:0)
请允许我为您提供略有不同的方法。子类CCNode到CCAppleNode和CCAppleNode.m文件中的子类检测触摸并在touchBegan上调用removeFromParent。通过这种方式,CCAppleNode类负责在触摸时将其自身从父项中删除,从主游戏场景中消除此责任。
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
[self removeFromParentAndCleanup:YES];
[super touchBegan:touch withEvent:event];
}