繁体   English   中英

预加载Spritekit纹理时遇到问题

[英]Trouble with preloading spritekit textures

我的初始视图控制器中的以下代码位于函数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停滞时,游戏就会停滞。 我是否正确预加载? 如果没有,我应该如何以及在哪里进行。

当预加载方法返回局部变量时,这些结构就是局部变量。 您需要使纹理对象保持“活动状态”(即使它们变为ivars)以进行预加载以具有所需的效果。

同样,如果这些纹理占用大量内存,则当加载更多纹理时,未使用的纹理可能会从内存中删除。 检查是否有任何内存通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM