我需要帮助--我试图删除一个在不同位置不断更新的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];
}
}
}发布于 2014-09-24 07:06:51
请允许我给您提供一个稍微不同的方法。子类CCNode到CCAppleNode并在CCAppleNode.m文件中检测触摸并调用touchBegan上的removeFromParent。通过这种方式,CCAppleNode类将在其触碰时承担起从父类中移除自己的责任,从而将此责任从您的主要游戏场景中删除。
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
[self removeFromParentAndCleanup:YES];
[super touchBegan:touch withEvent:event];
}https://stackoverflow.com/questions/26006562
复制相似问题