Jump to content
  • Advertisement
Sign in to follow this  

XCode 4.2 and referencing external files

This topic is 2002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello GameDev.net! You guys have always had more insight than I could have asked for into technical problems I've encountered in the past, so I figure I'll bounce this one off you too since A) I don't know the right vocab for a good Google search on this one, and B) That is a fact because all the Google searches I have done ended up having nothing to do with this problem. :P Making a cross post from MacRumors though since I would like to believe that forum knows more, but I have a solid faith in you guys too.

Anyways, I'm finally taking the dive and trying to learn how to port my C++ game to Mac via XCode. With sfml and opengl, that hasn't been too hard - but I use a custom file type that I read in with ifstream (although I've been told I should switch to fopen eventually) and while I have it working when I click Run in XCode, the OS X App itself does not know how to read in these files. More details below, but, any thoughts?


I am importing this project into XCode essentially, so I took a working SFML framework, added my files, swapped out the main and hit run. Amazingly, all the core stuff worked! The maps (external files in question) did not load though, and it ended up being due to the location of the working directory. Going into XCode's scheme and changing it to be the working dir I use for my old project itself, the maps began loading just fine (since all the map addresses are relative, ie "./maps/world1.map") when I clicked the Run button from inside XCode. Great! But I want to release the game eventually too.

Going into the Derived Data path, where ultimately under Derived Data/Project Folder/Build/Products/Debug I found myGame.app, a 75MB Intel App (so it appears to be sucking up all the music and sound effect files, since the example sfml project before would only make an 8MB app). Trying to run this file by double clicking though makes the project open, but no sound, music, maps, or images load (so none of the external files that were referenced in the working directory). Moving the app into the working directory does not fix this problem either.
So far I have been unable to find a way to build the app directly into the working directory, and am only able to influence its placement by changing Derived Data in Preferences for all of XCode. So, any tips on how to get my final product seeing files the same way that the one run out of XCode sees?

Oh, and as a final note: I'm trying to keep the maps folder separate so that I can easily release new packs of maps without asking people to redownload the whole game, or so that people can fiddle with them and make their own maps. Essentially, I'm trying to keep them visible to the user.

EDIT: And I was wrong! The game does not work flawlessly from XCode, only the first level (the one loaded when building the game) loads properly, every level after that fails to load. I'm guessing that's since after that point, the game is running from the dir where it was built to rather than the one it was built from. Edited by BlinksTale

Share this post

Link to post
Share on other sites
You want to release your project, right?

First you have to make sure that when debugging within XCode it is working flawlessly.
You said that only the first level is loading, and that is really strange. In my projects, I leave the assets/ folder inside MyApplication/MyApplication (where MyApplication is the name of your project) and it works fine.
When building the project, the assets must be copied to the bundle. So make sure that in XCode:
1) Click the Project Name in the Navigation Bar
2) Go to Build Phases
3) Go to Copy Bundle Resources and check if all the resources are listed there. Otherwise click the plus button and add the folder there.

I have never tried using an external resource (except when pulling something from the web and when I was using objective-c).
But I think here might be a start for you to look. This is objective-c though.

Now on to the Release build.
1) Check if your build settings are ok (architecture, etc.)
2) In Product -> Build for Archiving
3) If the above build is successful go to Product -> Archive
4) In the window that will pop up:
5) If you are going to release for App Store click the Validate... button
6) Otherwise you can directly click on Distribute and choose Direct Distribute
7) Choose Export As -> Application

That should work...
I have tried this with SDL before but not with SFML Edited by kuramayoko10

Share this post

Link to post
Share on other sites
And there was my problem! I was leaving all the files inside my Resources folder in the .app, but not the folders with my files. Deleted those, copied over the folders themselves this time including their contents (rather than just the contents) and all the levels load now :) Success!

Except, that's only in XCode. Now when I go to try the game as a standalone .app, it only manages to load things it was not initially asked to load. So, level 1, all the sound effects, music, and menu images fail to load, but levels 2 through the last level work fine. It's just for a demo, so no where near ready for the App store yet (though I appreciate that information!) but even so, having everything load is rather important. :P

I have two folders: my XCode project, and my old repo for the game (since I'm porting it to XCode). Currently XCode is using my old repo as the working dir, and when XCode runs the project, everything loads up. The standalone app loads everything but the initial load this way. I have had it suggested to me that I switch the working dir to MyGame.app/Contents/Resources, which would make sense given that everything is in there, but instead it makes XCode not load any of the initial contents *as well as* the standalone app, so it seems to make things worse.

I figure this thread is still close enough to the topic that I should ask this here too. Any thoughts on why this is, or how it relates?

Many thanks for the help so far kuramayoko10!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!