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

Author Topic: How to load files from macOS app bundle "Resource" folder?  (Read 2389 times)

0 Members and 1 Guest are viewing this topic.

wengwengweng

  • Newbie
  • *
  • Posts: 2
    • View Profile
How to load files from macOS app bundle "Resource" folder?
« on: November 22, 2018, 04:19:38 am »
I have a macos app bundle like this:

.
└── Contents
    ├── Frameworks
    ├── Info.plist
    ├── MacOS
    └── Resources
        ├── icon.icns
        └── sprites
            └── car.png
 

I can't load files by calling loadFromFile("sprites/car.png"), however I just tried in SDL using "sprites/*" just works. Now I can only use absolute path to make it work.
« Last Edit: November 22, 2018, 04:27:41 am by wengwengweng »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to load files from macOS app bundle "Resource" folder?
« Reply #1 on: November 22, 2018, 04:43:00 am »
I used Mac for like 15 minutes total in my life and an iPhone for like 2 hours but: https://www.sfml-dev.org/tutorials/2.5/start-osx.php

Quote
Header & source files: the project comes with a basic example in main.cpp and the helper function std::string resourcePath(void); in ResourcePath.hpp and ResourcePath.mm. The purpose of this function, as illustrated in the provided example, is to provide a convenient way to access the Resources folder of your application bundle.
Please note that this function only works on macOS. If you are planning to make your application work on other operating systems, you should implement your own version of this function on the operating systems in question.
Back to C++ gamedev with SFML in May 2023

wengwengweng

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to load files from macOS app bundle "Resource" folder?
« Reply #2 on: November 22, 2018, 06:08:14 am »
Thanks. I don't use xcode so I skipped that tutorial page... Got it working now.