在iOS框架

时间:2016-11-02 14:49:48

标签: ios swift

Evrything工作正常,直到我试图将我的资产(精灵表)放入iOS框架中。我正在使用Swift 3.0

为了减轻我的Xcode项目,我决定将我的资产:TexturePacker生成的sprite表放在框架中。当它们包含在主项目中时,作为内部资源,一切正常。但是当我把我的地图集放在一个框架中时,代码编译得很好,没有错误,应用程序在物理设备(iPad)上正常运行,但我有一个红十字而不是我的精灵。我从控制台收到以下错误消息:

2016-11-02 15:35:02.166测试拼图[310:42458]无法找到纹理图集“Statiques”。 2016-11-02 15:35:02.392测试拼图[310:42458]无法找到纹理图集'Puzzle0'。 2016-11-02 15:35:02.393测试拼图[310:42458]无法找到纹理图集'Puzzle1'。

等等(直到41)

我在我的课程之前放置了public关键字,并从主项目中调用了所有函数。这是一个例子......

import SpriteKit


public class Statiques {

public init() {

}

// sprite names
let DANCING1 = "Dancing1"
let DANCING2 = "Dancing2"
let PUZZLE0  = "Puzzle0"
let PUZZLE1  = "Puzzle1"
let PUZZLE10 = "Puzzle10"
let PUZZLE11 = "Puzzle11"
let PUZZLE12 = "Puzzle12"
let PUZZLE13 = "Puzzle13"
let PUZZLE14 = "Puzzle14"
let PUZZLE15 = "Puzzle15"
let PUZZLE16 = "Puzzle16"
let PUZZLE17 = "Puzzle17"
let PUZZLE18 = "Puzzle18"
let PUZZLE19 = "Puzzle19"
let PUZZLE2  = "Puzzle2"
let PUZZLE20 = "Puzzle20"
let PUZZLE21 = "Puzzle21"
let PUZZLE22 = "Puzzle22"
let PUZZLE23 = "Puzzle23"
let PUZZLE24 = "Puzzle24"
let PUZZLE25 = "Puzzle25"
let PUZZLE26 = "Puzzle26"
let PUZZLE27 = "Puzzle27"
let PUZZLE28 = "Puzzle28"
let PUZZLE29 = "Puzzle29"
let PUZZLE3  = "Puzzle3"
let PUZZLE30 = "Puzzle30"
let PUZZLE31 = "Puzzle31"
let PUZZLE32 = "Puzzle32"
let PUZZLE33 = "Puzzle33"
let PUZZLE34 = "Puzzle34"
let PUZZLE35 = "Puzzle35"
let PUZZLE36 = "Puzzle36"
let PUZZLE37 = "Puzzle37"
let PUZZLE38 = "Puzzle38"
let PUZZLE39 = "Puzzle39"
let PUZZLE4  = "Puzzle4"
let PUZZLE40 = "Puzzle40"
let PUZZLE41 = "Puzzle41"
let PUZZLE5  = "Puzzle5"
let PUZZLE6  = "Puzzle6"
let PUZZLE7  = "Puzzle7"
let PUZZLE8  = "Puzzle8"
let PUZZLE9  = "Puzzle9"


// load texture atlas
let textureAtlas = SKTextureAtlas(named: "Statiques")


// individual texture objects
public func Dancing1() -> SKTexture { return textureAtlas.textureNamed(DANCING1) }
public func Dancing2() -> SKTexture { return textureAtlas.textureNamed(DANCING2) }
public func Puzzle0() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE0) }
public func Puzzle1() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE1) }
public func Puzzle10() -> SKTexture { return textureAtlas.textureNamed(PUZZLE10) }
public func Puzzle11() -> SKTexture { return textureAtlas.textureNamed(PUZZLE11) }
public func Puzzle12() -> SKTexture { return textureAtlas.textureNamed(PUZZLE12) }
public func Puzzle13() -> SKTexture { return textureAtlas.textureNamed(PUZZLE13) }
public func Puzzle14() -> SKTexture { return textureAtlas.textureNamed(PUZZLE14) }
public func Puzzle15() -> SKTexture { return textureAtlas.textureNamed(PUZZLE15) }
public func Puzzle16() -> SKTexture { return textureAtlas.textureNamed(PUZZLE16) }
public func Puzzle17() -> SKTexture { return textureAtlas.textureNamed(PUZZLE17) }
public func Puzzle18() -> SKTexture { return textureAtlas.textureNamed(PUZZLE18) }
public func Puzzle19() -> SKTexture { return textureAtlas.textureNamed(PUZZLE19) }
public func Puzzle2() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE2) }
public func Puzzle20() -> SKTexture { return textureAtlas.textureNamed(PUZZLE20) }
public func Puzzle21() -> SKTexture { return textureAtlas.textureNamed(PUZZLE21) }
public func Puzzle22() -> SKTexture { return textureAtlas.textureNamed(PUZZLE22) }
public func Puzzle23() -> SKTexture { return textureAtlas.textureNamed(PUZZLE23) }
public func Puzzle24() -> SKTexture { return textureAtlas.textureNamed(PUZZLE24) }
public func Puzzle25() -> SKTexture { return textureAtlas.textureNamed(PUZZLE25) }
public func Puzzle26() -> SKTexture { return textureAtlas.textureNamed(PUZZLE26) }
public func Puzzle27() -> SKTexture { return textureAtlas.textureNamed(PUZZLE27) }
public func Puzzle28() -> SKTexture { return textureAtlas.textureNamed(PUZZLE28) }
public func Puzzle29() -> SKTexture { return textureAtlas.textureNamed(PUZZLE29) }
public func Puzzle3() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE3) }
public func Puzzle30() -> SKTexture { return textureAtlas.textureNamed(PUZZLE30) }
public func Puzzle31() -> SKTexture { return textureAtlas.textureNamed(PUZZLE31) }
public func Puzzle32() -> SKTexture { return textureAtlas.textureNamed(PUZZLE32) }
public func Puzzle33() -> SKTexture { return textureAtlas.textureNamed(PUZZLE33) }
public func Puzzle34() -> SKTexture { return textureAtlas.textureNamed(PUZZLE34) }
public func Puzzle35() -> SKTexture { return textureAtlas.textureNamed(PUZZLE35) }
public func Puzzle36() -> SKTexture { return textureAtlas.textureNamed(PUZZLE36) }
public func Puzzle37() -> SKTexture { return textureAtlas.textureNamed(PUZZLE37) }
public func Puzzle38() -> SKTexture { return textureAtlas.textureNamed(PUZZLE38) }
public func Puzzle39() -> SKTexture { return textureAtlas.textureNamed(PUZZLE39) }
public func Puzzle4() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE4) }
public func Puzzle40() -> SKTexture { return textureAtlas.textureNamed(PUZZLE40) }
public func Puzzle41() -> SKTexture { return textureAtlas.textureNamed(PUZZLE41) }
public func Puzzle5() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE5) }
public func Puzzle6() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE6) }
public func Puzzle7() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE7) }
public func Puzzle8() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE8) }
public func Puzzle9() -> SKTexture  { return textureAtlas.textureNamed(PUZZLE9) }


// texture arrays for animations
public func Dancing() -> [SKTexture] {
    return [
        Dancing1(),
        Dancing2()
    ]
}

public func Puzzle() -> [SKTexture] {
    return [
        Puzzle0(),
        Puzzle1(),
        Puzzle2(),
        Puzzle3(),
        Puzzle4(),
        Puzzle5(),
        Puzzle6(),
        Puzzle7(),
        Puzzle8(),
        Puzzle9(),
        Puzzle10(),
        Puzzle11(),
        Puzzle12(),
        Puzzle13(),
        Puzzle14(),
        Puzzle15(),
        Puzzle16(),
        Puzzle17(),
        Puzzle18(),
        Puzzle19(),
        Puzzle20(),
        Puzzle21(),
        Puzzle22(),
        Puzzle23(),
        Puzzle24(),
        Puzzle25(),
        Puzzle26(),
        Puzzle27(),
        Puzzle28(),
        Puzzle29(),
        Puzzle30(),
        Puzzle31(),
        Puzzle32(),
        Puzzle33(),
        Puzzle34(),
        Puzzle35(),
        Puzzle36(),
        Puzzle37(),
        Puzzle38(),
        Puzzle39(),
        Puzzle40(),
        Puzzle41()
    ]
}


}

从我的主应用程序中,我使用以下代码调用框架:

import Foundation
import SpriteKit
import AVFoundation
import Framework_Dancing


class GameScene1: GameScene {

// not useful code for this problem is missing here...

let sheet = Statiques()

let sprite_dancing1 = SKPuzzleAnim(texture: sheet.Dancing1())
let sprite_dancing2 = SKPuzzleAnim(texture: sheet.Dancing2())

我的框架是130 MB,让我觉得资产正确包含在其中,我没有得到编译器的错误,我对框架缺少什么?一旦我将资产放入主项目,没有框架,一切都很好。

所有地图集都是由TexturePacker生成的。

以下是我的Xcode项目的屏幕副本,其中包含框架中的代码:

Screen copy

感谢您的帮助,

皮尔

2 个答案:

答案 0 :(得分:0)

我相信您会收到错误,因为您正在寻找主项目中的资产,而不是框架项目中的资产。

例如,如果要显示存储在框架中的UIImage,则必须编写此

let image = UIImage(named: "SomeImage", in: Bundle(identifier: "FrameworkBundleID"), compatibleWith: nil)

您可以在此处详细了解

cocoa touch framework assets not visible in App Project

问题是SKNode / SKSpriteNode等没有类似的初始化程序,因此我不确定它是否可行。

希望这有帮助

答案 1 :(得分:0)

以下是我从TexturePacker的创建者那里得到的回复:

"据我所知,SKTextureAtlas构造函数总是在主应用程序中搜索其atlas文件,即使它是在框架代码中调用的。我不知道这是一个错误还是一个功能,你不得不问苹果。抱歉,我无法帮助您解决这个问题: - / 最好的祝福, 勒夫"