SpriteKit内存pipe理预加载caching和fps问题

我的问题非常简单,根据苹果文档,您可以在呈现如下场景之前将纹理预加载到RAM中:

SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:@"effect_circle_explode"]; SKTextureAtlas * atlas2 = [SKTextureAtlas atlasNamed:@"box_explodes"]; SKTextureAtlas * atlas3 = [SKTextureAtlas atlasNamed:@"fence_new"]; SKTextureAtlas * atlas4 = [SKTextureAtlas atlasNamed:@"swipe"]; SKTextureAtlas * atlas5 = [SKTextureAtlas atlasNamed:@"coin"]; SKTextureAtlas * atlas6 = [SKTextureAtlas atlasNamed:@"two_times"]; SKTextureAtlas * atlas7 = [SKTextureAtlas atlasNamed:@"three_times"]; SKTextureAtlas * atlas8 = [SKTextureAtlas atlasNamed:@"gus"]; [SKTextureAtlas preloadTextureAtlases:@[atlas, atlas2, atlas3, atlas4, atlas5, atlas6, atlas7, atlas8] withCompletionHandler:^{ [moron_logo removeFromSuperview]; moron_logo = NULL; stuff.hidden = NO; store.hidden = NO; scroll_view.userInteractionEnabled = YES; [self present_game_view]; }]; 

现在,如果以后通过游戏玩法,你还可以调用预加载到相同的地图集:

 -(void)load { SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:@"effect_circle_explode"]; SKTextureAtlas * atlas2 = [SKTextureAtlas atlasNamed:@"coin"]; [SKTextureAtlas preloadTextureAtlases:@[atlas, atlas2] withCompletionHandler:^{ explode_textures = [[NSMutableArray alloc] init]; int numImages = (int)atlas.textureNames.count; for (int i=0; i <= numImages/2-1; i++) { NSString *textureName = [NSString stringWithFormat:@"effect_circle_explode_%d.png", i]; SKTexture *temp = [atlas textureNamed:textureName]; [explode_textures addObject:temp]; } explodeAnimation = [SKAction animateWithTextures:explode_textures timePerFrame:.05]; idle_textures = [[NSMutableArray alloc] init]; int numImages2 = (int)atlas.textureNames.count; for (int i=0; i <= numImages2/2-1; i++) { NSString *textureName = [NSString stringWithFormat:@"coin_%d.png", i]; SKTexture *temp = [atlas2 textureNamed:textureName]; [idle_textures addObject:temp]; } idleAnimation = [SKAction animateWithTextures:idle_textures timePerFrame:.05]; [self animate:0]; }]; } 

现在,如果我不再预先加载纹理,那么游戏实际上会在一段时间内崩溃,而不是所有的时间,如果我只是直接插入到SKAction的纹理。 崩溃是Sprite :: update(double)调用的exec_bad_access,所以我的假设是,第一次预加载的纹理已经从RAM中删除了,这就是为什么我每次都预加载一个新的节点。 它似乎已经修复了这个错误。 这导致了另一个问题,虽然当涉及到performance,因此我这样问的原因。

游戏运行良好的5S和5,但只要你触摸iPod touch的第五代,它几乎不能超过15 FPS。 我跑了仪器,这是什么吃了所有的CPU时间: 在这里输入图像说明 这可能与我preloadatlas呼叫的不断呼叫有关吗? 有谁知道为什么这会吃我的处理器时间在旧设备上如此糟糕? 非常感谢,希望别人可能会有类似的问题,这将帮助他们,一旦我让我的方式底部。

提前致谢。

每次创build一个新的精灵时,预加载地图集通常是一个坏主意。

你的实际问题似乎是你预先载入地图集,但是你不要把它们放在附近。 除非地图集variables是全局的。

只要执行预加载的方法返回,地图集对象现在被更长的引用,并将自动从内存中移除。 Sprite Kit在内部实现了一个caching系统,所以你不会马上注意到,但最终一个或多个地图集将会消失。

保持对场景中的每个图集的强有力的参考,以便地图集保留在内存中,并在运行时停止预加载。 这是否有助于与FPS我不知道。