Error loading image in SpriteKit Hello World

I created a new xcode project "game" and I am trying to make a really simple "Hello World" where I display an image on the screen.

My image is not loading. Mistake:SKTexture: Error loading image resource: "img/flappy1.png"

The code is an exact copy of the tutorial in which it works. Did I forget something?

My code:

enter image description here

My image:

enter image description here

When I run the application:

enter image description here

+3


source to share


2 answers


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

What looks like folders in the Xcode organizer are not actually folders on disk, but instead "groups" that only exist within Xcode.

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



So:

var birdTexture = SKTexture(imageNamed: "flappy1.png")

      

+1


source


A similar error message will occur if you have two targets (eg iOS, macOS), "Target Membership" was not set to include both for assets.



0


source







All Articles