I have this code inside of my initial view controller, in the function 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];
}];
And I want to load these textures before my game starts so that I do not have lag during the gameplay. However this does not appear to be working because whenever new spritenodes that are made from images found in my obstacleAtlas the game lags. Am I preloading correctly? If not, how and where should I be doing this.