簡體   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