Everything was working fine until I tried to put my assets (sprite sheets) inside an iOS framework. I'm using Swift 3.0
To lighten my Xcode project, I have decided to put my assets: sprite sheets produced by TexturePacker inside a framework. When they are include in the main project, as internal resources, everything is working fine. But when I put my atlas inside a framework, the code is compiling fine, no error, the app is running fine on the physical device (an iPad) but I have a red cross instead of my sprites. I get the following error message from the console:
2016-11-02 15:35:02.166 Test Puzzles[310:42458] Texture Atlas 'Statiques' cannot be found.
2016-11-02 15:35:02.392 Test Puzzles[310:42458] Texture Atlas 'Puzzle0' cannot be found.
2016-11-02 15:35:02.393 Test Puzzles[310:42458] Texture Atlas 'Puzzle1' cannot be found.
etc., etc. (until 41)
I have put the public keyword before my class and all the functions called from the main project. Here is an example...
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()
]
}
}
From my main app, I call the framework with this code:
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())
My framework is 130 MB, which let me think the assets are correctly included inside it, I get no error from the compiler, what am I missing with the framework? As soon as I put the assets into the main project, without the framework, everything is OK.
All the atlas has been generated by TexturePacker.
Here is a screen copy of my XCode project with the code from the framework:
Thanks for your help
Here is the reply I got from the creators of TexturePacker:
"as far as I know the SKTextureAtlas constructor always searches its atlas file in the main app, even if it is called in the framework code. I don't know if this is a bug or a feature, you would have to ask Apple. I'm sorry, but I can't help you with this issue :-/ Best regards, Joachim"