SpriteKit unarchiveFromFileは、アセットカタログおよびアトラスからテクスチャをロードしません

サラムホラニ

私はまだSpriteKitを初めて使用しているので、XcodeのSKSエディターを使用してレベルを作成できるかどうかを確認したいと思いました。「Spaceship.png」テクスチャを使用してスプライトをいくつか追加し、テンプレートアプリを作成すると、テクスチャが読み込まれません。

これは、言語としてSwiftを使用し、提供されている「Spaceship.png」スプライトを追加したバニラOSXゲームテンプレートのスクリーンショットです。テクスチャはきれいに表示されます。スプライトテクスチャがSKSceneエディタで正常に表示されるテンプレートを変更しただけでアプリをビルドして実行した結果は次のとおりです。ここに画像の説明を入力してください

The debug console displays this warning message: ここに画像の説明を入力してください I tried to add an .atlas folder, and got the same result. the scene just displays the red X icon in place of the sprite. If the added sprites where just color sprites, they display fine. I had an app some time ago that I scrapped, where I used to load the SKScene and would manually add the sprite assets within to my SKScene sub-class, and it worked fine.

If, however, i moved the textures - "Spaceship.png" as an example - to the root of the project, i.e. not inside an asset catalogue or .atlas folder, the scene loads with the textures displaying fine.

Here's the texture added to the root of the project:

ここに画像の説明を入力してください

And this is the desired result: ここに画像の説明を入力してください I tried to manually add the loaded assets from the SKS file to the scene via enumerateChildNodesWithName(_,usingBlock) and I get the same result if the textures were not in the root of the project folder.

This is me trying to add the assets manually:

    func applicationDidFinishLaunching(aNotification: NSNotification) {
    /* Pick a size for the scene */
    if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
        let sceneToBePresented = GameScene()

        /* Set the scale mode to scale to fit the window */
        sceneToBePresented.scaleMode = .AspectFill
        sceneToBePresented.size = scene.size

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        self.skView!.ignoresSiblingOrder = true

        self.skView!.showsFPS = true
        self.skView!.showsNodeCount = true
        scene.enumerateChildNodesWithName("*") { node, stop in
            sceneToBePresented.addChild(node.copy() as SKSpriteNode)
        }

        self.skView!.presentScene(sceneToBePresented)
    }
}

I looked around SpriteKit classes - SKNode, SKScene, SKTexture, SKSPriteNode - for any clue about paths, caching, preloading, or anything but was unable to find a thing that could make this work.

I am running Xcode 6.1.1 and my target is 10.9, and the language I'm using is Swift, although the same behavior holds true using ObjC. Is this a feature or a bug? Anybody else running/ran into a similar situation ?

Thanks in advance for any help

[UPDATE]

Looks like this is not implemented yet - loading textures from asset catalogs - as this post in the dev forums discusses the same issue, and his solution is to rename the asset catalogues to be the same name as the texture. In essence, what I found out about having the image files in the root folder: How do you load sprite textures from Images.xcassets when using SKS scene file, although my earlier app which i managed to roll-back to a working state does load textures from .atlas'es, but i can't seem to do it with a clean template!!!

Salam Horani

[Answering my own question here]

As far as I can tell, at this moment, loading texture from asset catalogues - Images.xcassets - while unarchiving or deserializing an SKScene file does not work on OSX based on my attempts and the devforumns post referenced above.

Loading of the textures from image atlases, however, works by forcing SKTexture to load the image. Forcing or 'touch'ing SKTexture can be done via the preloadWithCompletionHandler(_:) or preloadTextures(_:, withCompletionHandler:) methods, or simply by printing the description of the sprite's SKTexture as i have discovered.

For the benefit of anybody who might need further assistance, here is a code snippet that preloads the textures after unarchiving an SKS file:

if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
    for child in scene.children as [SKNode] {
        if child is SKSpriteNode {
            let sprite = child as SKSpriteNode
            sprite.texture?.preloadWithCompletionHandler({ })
            /* or even a simple debug log of the texture */
            /* println(sprite.texture) */
        }
    }
    /* Do your other stuff ... */
    ...
}

私が間違っている場合は私を訂正してください。誰かがそうするか、AppleがiOSとOSXの間のSpriteKitの動作の不一致を修正するまで、私は別の解決策を探すことはなく、マーフィーの法則に従います。

それが機能する場合は、修正しないでください

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

「テンプレートレンダリングはテクスチャアトラスではサポートされていません」SpriteKitおよびXcode

分類Dev

SpriteKit:テクスチャアトラスは2番目のターゲットにロードされません

分類Dev

Spritekitテクスチャアトラスからテクスチャをロードする最もパフォーマンスの高い方法

分類Dev

SpriteKitを使用したカスタムフレームワーク-アセットファイルがロードされていません

分類Dev

誰かが現在のSpriteKitテクスチャアトラスサンプルを共有して引き離してくれませんか

分類Dev

SpriteKitテクスチャアトラスと画像xcassets

分類Dev

SpriteKitテクスチャアトラスフォルダ構造

分類Dev

SpriteKitレベルエディタテクスチャアトラス

分類Dev

SKSpriteNodeとテクスチャアトラスによる高いSpriteKit描画カウント

分類Dev

実行時にSpriteKitテクスチャアトラスを作成できますか

分類Dev

SpriteKit-スプライトをタッチ位置から押し出します

分類Dev

SpriteKit、プロセスを別のコアに配置しますか?

分類Dev

フレーム全体ではなく、スプライトテクスチャ内のタッチを検出しますiOS Swift SpriteKit?

分類Dev

SpriteKitからSpringboardへ

分類Dev

Spritekitプロジェクトでプログラムでテクスチャの色相を変更することは可能ですか?

分類Dev

SpriteKitのシーン

分類Dev

SpriteKitのカスタムクラスでコード化可能なプロトコルを使用する

分類Dev

ペースの速いSpriteKitゲームはCPUアクティビティが不規則で、フレームレートが高いままであるにもかかわらず、ジッター/ラグがあります-Swift

分類Dev

iOSのSpriteKitで、テクスチャスプライトをスケーリングすると誤ったフレームが生成されますか?

分類Dev

カテゴリビットマスクはSpriteKitでどのように機能しますか?(0xFFFFFFFF)

分類Dev

SpriteKitでアニメーションを実行した後、スプライトのテクスチャが変化しない

分類Dev

SpriteKitの別のクラスまたはシーンからvarにアクセスする

分類Dev

Spritekit-タッチ開始時の衝突アプローチ

分類Dev

XcodeでパーティクルエフェクトをSpriteKitノードにアタッチする方法

分類Dev

SpriteKit部分テクスチャマッピング

分類Dev

SpriteKitにグローバルに複数のスプライトを追加する方法はありますか?

分類Dev

視差スクロールSpriteKit

分類Dev

Spritekit並列スクロール

分類Dev

spritekitはバックグラウンド状態から印刷を取得できません

Related 関連記事

  1. 1

    「テンプレートレンダリングはテクスチャアトラスではサポートされていません」SpriteKitおよびXcode

  2. 2

    SpriteKit:テクスチャアトラスは2番目のターゲットにロードされません

  3. 3

    Spritekitテクスチャアトラスからテクスチャをロードする最もパフォーマンスの高い方法

  4. 4

    SpriteKitを使用したカスタムフレームワーク-アセットファイルがロードされていません

  5. 5

    誰かが現在のSpriteKitテクスチャアトラスサンプルを共有して引き離してくれませんか

  6. 6

    SpriteKitテクスチャアトラスと画像xcassets

  7. 7

    SpriteKitテクスチャアトラスフォルダ構造

  8. 8

    SpriteKitレベルエディタテクスチャアトラス

  9. 9

    SKSpriteNodeとテクスチャアトラスによる高いSpriteKit描画カウント

  10. 10

    実行時にSpriteKitテクスチャアトラスを作成できますか

  11. 11

    SpriteKit-スプライトをタッチ位置から押し出します

  12. 12

    SpriteKit、プロセスを別のコアに配置しますか?

  13. 13

    フレーム全体ではなく、スプライトテクスチャ内のタッチを検出しますiOS Swift SpriteKit?

  14. 14

    SpriteKitからSpringboardへ

  15. 15

    Spritekitプロジェクトでプログラムでテクスチャの色相を変更することは可能ですか?

  16. 16

    SpriteKitのシーン

  17. 17

    SpriteKitのカスタムクラスでコード化可能なプロトコルを使用する

  18. 18

    ペースの速いSpriteKitゲームはCPUアクティビティが不規則で、フレームレートが高いままであるにもかかわらず、ジッター/ラグがあります-Swift

  19. 19

    iOSのSpriteKitで、テクスチャスプライトをスケーリングすると誤ったフレームが生成されますか?

  20. 20

    カテゴリビットマスクはSpriteKitでどのように機能しますか?(0xFFFFFFFF)

  21. 21

    SpriteKitでアニメーションを実行した後、スプライトのテクスチャが変化しない

  22. 22

    SpriteKitの別のクラスまたはシーンからvarにアクセスする

  23. 23

    Spritekit-タッチ開始時の衝突アプローチ

  24. 24

    XcodeでパーティクルエフェクトをSpriteKitノードにアタッチする方法

  25. 25

    SpriteKit部分テクスチャマッピング

  26. 26

    SpriteKitにグローバルに複数のスプライトを追加する方法はありますか?

  27. 27

    視差スクロールSpriteKit

  28. 28

    Spritekit並列スクロール

  29. 29

    spritekitはバックグラウンド状態から印刷を取得できません

ホットタグ

アーカイブ