我在初始视图控制器中有这个代码,在函数viewWillLayoutSubviews中:
SKTextureAtlas *obstacleAtlas = [SKTextureAtlas atlasNamed:@"gonImages"];
obstacleAtlas = [SKTextureAtlas atlasNamed:@"gonImages"];
SKTexture *castle = [obstacleAtlas textureNamed:@"castle@2x.png"];
SKTexture *column = [obstacleAtlas textureNamed:@"columnNE@2x.png"];
SKTexture *factory = [obstacleAtlas textureNamed:@"factory@2x.png"];
SKTexture *hotAirBallon = [obstacleAtlas textureNamed:@"hotAirBallon@2x.png"];
SKTexture *lightningBolt = [obstacleAtlas textureNamed:@"lightningBolt@2x.png"];
SKTexture *pirateShip = [obstacleAtlas textureNamed:@"pirateShip@2x.png"];
SKTexture *pyramidNE = [obstacleAtlas textureNamed:@"PyramidNE@2x.png"];
SKTexture *rocket = [obstacleAtlas textureNamed:@"rocket@2x.png"];
SKTexture *sun = [obstacleAtlas textureNamed:@"sun@2x.png"];
SKTexture *wheel = [obstacleAtlas textureNamed:@"wheel@2x.png"];
NSArray *obstacleTextures = @[castle, column, factory, hotAirBallon, lightningBolt, pirateShip, pyramidNE, rocket, sun, wheel];
[SKTexture preloadTextures:obstacleTextures withCompletionHandler:^{
// Present the scene.
[skView presentScene:startScene];
//[skView presentScene:scene];
}];
我想在游戏开始之前加载这些纹理,以便在游戏过程中没有滞后。然而,这似乎并不起作用,因为每当从我的障碍物中发现的图像制作的新spritenode时,游戏就会滞后。我正确预装吗?如果没有,我应该如何以及在哪里这样做。
答案 0 :(得分:1)
这些tectures是局部变量,当预加载方法返回时,ARC释放局部变量。您需要保持纹理对象“活着”(即使它们成为ivars)以进行预加载以获得所需的效果。
此外,如果这些纹理消耗大量内存,则可能会在加载更多纹理时从内存中删除未使用的内存。检查是否有任何内存通知。