遇到了一些奇怪的性能问题:
NSMutableDictionary* creatureNodeDict // all my currently drawn sprites that are moving
在编译了所有可以在keyArr中看到的精灵之后,我删除那些移出屏幕的精灵,如下所示:
NSMutableArray* spritesToDel = [NSMutableArray arrayWithArray:self.creatureNodeDict.allKeys] ;
[spritesToDel removeObjectsInArray:keyArr];
然后在循环中删除它们,如:
for (NSString* key in spritesToDel) {
SKSpriteNode* node = [self.creatureNodeDict objectForKey:key];
[node removeFromParent];
}
现在这个速度非常慢,就像700个精灵的速度慢500毫秒。
答案 0 :(得分:1)
当我自己用一个简单的伎俩尝试时,我正要问是否有人有任何建议:
NSMutableArray* spritesToRemoveArray = [[NSMutableArray alloc] init];
for (NSString* key in spritesToDel) {
SKSpriteNode* node = [self.creatureNodeDict objectForKey:key];
if (node.parent == mainParentNode) {
[spritesToRemoveArray addObject:node];
}
else {
AFLog(@"parent %@ is not map", node.parent);
[node removeFromParent];
}
}
[mainParentNode removeChildrenInArray:spritesToRemoveArray];
现在删除500-800个精灵需要20-40毫秒!