我的问题很简单,根据苹果文档,在呈现这样的场景之前,您有能力将纹理预加载到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,因此我的假设是,第一个预加载中的纹理以某种方式从内存中删除,这就是为什么我现在每次创建一个新节点时都预加载的原因。似乎已经修正了这个错误。这导致了另一个问题,但当涉及到性能,因此,我为什么要问这个问题。
游戏运行良好的5S和5,但一旦你触摸一个iPod触摸第5代,它几乎不能超过15 FPS。我运行仪器,这就是消耗所有CPU时间的原因:

这可能与我不断调用预装图集电话有关吗?有人知道为什么这会让我的处理器时间在旧设备上消耗得如此之大吗?非常感谢,希望其他人也会有类似的问题,这将帮助他们,一旦我找到了我的解决办法。
提前谢谢。
发布于 2014-01-13 20:14:08
每次创建一个新的精灵时,预置地图集通常都是个坏主意。
您的实际问题似乎是预先加载了地图集,但没有保留它们。除非地图集变量是全局的。
当完成预加载的方法返回时,地图集对象将被更长时间引用,并将自动从内存中删除。Sprite在内部实现了一个缓存系统,所以您不会立即注意到它,但最终会有一个或多个地图集消失。
保持对场景中每本地图集的强烈引用,以便地图集保留在内存中,并在运行时停止预装。这对我不知道的fps是否有帮助。
https://stackoverflow.com/questions/21098880
复制相似问题