Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: xcode image loading error  (Read 4109 times)

0 Members and 1 Guest are viewing this topic.

Prummi

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
xcode image loading error
« on: February 04, 2018, 11:46:06 am »
Hello,

I bought a book (SFML game development) and I can't get trough the first chapter. I need to load an image and a font but both of them won't load. The errors;

Failed to load image "Media/Textures/Eagle.png". Reason: Unable to open file
Failed to load font "Media/Sansation.ttf" (failed to create the font face)

I work in xCode. I don't know if this could be the problem but this is how I worked;
- I made a folder in finder called Media, in which I put the Textures map and put it all in (without involving xcode).

I made sure that hide file extension is checked off. I tried to put the Media folder in the folder in which the *projectName*.xcodeproj is, and in the folder where the files are but both ways didn't work.

Could anyone help me out please?

Pinco

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: xcode image loading error
« Reply #1 on: February 04, 2018, 01:07:11 pm »
Try using the whole path, I'm not really familiar with xCode but I'll try to help.

Also try posting minimal code so that we can get an idea of what you are doing wrong.
« Last Edit: February 04, 2018, 01:10:00 pm by Pinco »
My potato is 5 petaflops faster than your high end pc.
https://imgur.com/gallery/0S5spVm

Prummi

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: xcode image loading error
« Reply #2 on: February 04, 2018, 02:48:35 pm »
the code:

if (!mTexture.loadFromFile("Media/Textures/Eagle.png"))
mFont.loadFromFile("Media/Sansation.ttf");

folder structure:
*project name* contains [ExternalLibraries], [Media], [*project name], [.xcodeproj file]
media contains Sansation.ttf and [Textures]
Textures folder contains Eagle.png

I tried the whole path, which is:
if (!mTexture.loadFromFile("/Users/Prummi/Desktop/dev/C++/SFML/SFML Game Development Book/Media/Textures"))
but this didn't work. It gave me the same error (unable to open file)

Pinco

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: xcode image loading error
« Reply #3 on: February 04, 2018, 09:47:03 pm »
Quote
I tried the whole path, which is:
if (!mTexture.loadFromFile("/Users/Prummi/Desktop/dev/C++/SFML/SFML Game Development Book/Media/Textures"))
but this didn't work. It gave me the same error (unable to open file)

You didn't put the file name though, try: "/Users/Prummi/Desktop/dev/C++/SFML/SFML Game Development Book/Media/Textures/Eagle.png"
My potato is 5 petaflops faster than your high end pc.
https://imgur.com/gallery/0S5spVm

Prummi

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: xcode image loading error
« Reply #4 on: February 04, 2018, 11:11:28 pm »
Ohh wow that's a pretty silly mistake, but thanks a lot! It finally works now. Is there any reason why I need to use the whole path? As the book I'm reading doesn't say or notice this. And is there a way around this?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: xcode image loading error
« Reply #5 on: February 08, 2018, 05:16:23 pm »
Have a look at the official tutorial for macOS and Xcode, we provide specific tools for that OS to deal with resources.
SFML / OS X developer

 

anything