Donny P Donny P - 1 year ago 212
iOS Question

Error loading image in SpriteKit Hello World

I've created a new "game" xcode project, and I'm trying to do a really simple "Hello World" where I display an image on the screen.

My image does not load. Error:

SKTexture: Error loading image resource: "img/flappy1.png"

The code is an exact copy of a tutorial where it works. Am I forgetting something?

My code:

enter image description here

My image:

enter image description here

When I run the app:

enter image description here

Answer Source

Try "flappy1.png" instead of "img/flappy1.png".

The things that look like folders in Xcode's organizer are not actually folders on disk, but instead "groups" that exist only within Xcode.

In addition to this, when an asset is added to a project in Xcode, the project stores a path to the asset, and it can be loaded without an absolute path.


var birdTexture = SKTexture(imageNamed: "flappy1.png")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download