Search code examples
iosswiftsprite-kitios-frameworksasset-catalog

Custom framework using SpriteKit - asset files not loaded


I created a cocoa touch framework project, which uses SpriteKit and includes image assets. (It's a framework because the idea is to create a mini game that I can add to different apps). I am testing it with a sample project that uses this framework.
My problem is at runtime - when I create a sprite with an image I get an error:

SKTexture: Error loading image resource XXXXX

I am using SKSpriteNode(imageNamed:"XXXXXX"). the images are in the bundle of the framework in a folder. I tried also putting them in an asset catalog. nothing works.

Any ideas what the problem is?


Solution

  • Well since you can get the desired asset from the framework as a UIImage, couldn't you just

    let image = UIImage(named: "image", in: type(of: self), compatibleWith: nil) 
    let texture = SKTexture(image: image)
    let sprite = SKSpriteNode(texture: texture)