skip to Main Content

I’m new to XCode. The version I’m using is 13.4.1. I’d like to access the assets from the binary. The application is written in standard C++. The resources don’t appear to be copied to a relative path and I’m not using an API like Qt that has it’s own resource management.

2

Answers


  1. Chosen as BEST ANSWER

    So busy this question went unanswered a while after the solution was found. Another developer with more XCode experience helped me.

    You can define macros in XCode project configuration that are expanded by the IDE when the code is built. In my case I needed to get the project root directory and use an offset to access a file. What I did was create a macro in XCode and assigned it the project's path using an XCode built-in variable.

    Now anyone can use that macro to access files in the asset directory and know it'll always be a valid path on another developer's machine.


  2. Try to reference to the complete path of the image, atleast that’s how I got it working:

        SDL_Surface* tmpSurface = IMG_Load("/Users/markcash/Documents/C++ Code/SDL_test/Assets/player.png");
    playerTex = SDL_CreateTextureFromSurface(renderer, tmpSurface);
    SDL_FreeSurface(tmpSurface);
    

    I should note that I’m using the libraries:

    #include "SDL2/SDL.h"
    #include "SDL_image.h"
    

    in my project to make use of the IMG_Load() function.

    Try to see how you can implement those libraries into Xcode:
    here’s a video that should help you in implementing SDL.h into your ‘framework’: https://youtu.be/44tO977slsU
    The process for adding the "SDL_image.h" library into your framework should be the same.

    SDL2 can be downloaded from here:
    https://github.com/libsdl-org/SDL/releases/tag/release-2.24.2
    (make sure to pick the ‘SDL2-2.24.2.dmg’ option if you’re using a Mac)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search