Reputation: 3045
I'm working on a game which up to now I've got my assets in the XCode project as usual, but I'm wondering if loading them at run time might be possible but I have no idea how to do this. I'm using the parse.com service so actually storing the assets online and loading them is fine, but how does that work in regards to the project being compiled? or the XCode project knowing that the assets are actually part of the program after they have been loaded?
Upvotes: 1
Views: 5112
Reputation: 2314
In case of image assets, you can use Coredata as back-end and store the images as blob type. If you want to update the images frequently or need to load the images on demand, then you can keep the images in server and use SDWebImage library to download or display.
If you plan to load images on demand then your app will require internet connection to work.
Now it is your choice to decide the architecture :)
Upvotes: 0
Reputation: 13222
When assets are part of the application bundle, they add up to the size of the IPA file. Size of the IPA matters in case of OTA. Currently the OTA size limit is 50MB. For a game, the asset size may run typically into hundred's of MBs which will restrict OTA download from app store.
Therefore applications download the required assets on first run of the game and store them on disk. For this method, application needs to implement asset download module with resume capabilities(for error handling or partial download scenarios) and caching techniques.
Bundled assets
To access the bundled resource you need to use code similar to
NSString *imgBundlePath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"someimage.png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imgBundlePath];
Downloaded assets
When an application downloads the resources from a server, downloaded files need to be stored in the application directory. They cannot be stored in the bundle as it is read-only once installed on device. To access these files code is
// Assuming downloaded assets are stored in NSCachesDirectory
NSArray *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *imgPath = [[cachePath lastObject] stringByAppendingPathComponent:@"someimage.png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imgBundlePath];
Hope I have answered your question.
Upvotes: 4