I'm using cocos2d for a little IOS game I'm developing. I like to have my assets splitted in differnt directories like:
Levels/Level1/gfx
Levels/Level1/sounds
Levels/Level1/maps
etc...
So, I have created this directories inside the Resources one. The problem is that I'm unable to load anything if the asset is not inside Resources directory. I mean Resources/image.png will load but Resources/images/image.png won't.
As a cocos2d example, [sprite spriteFromFile:#"image.png"] will load but [sprite spriteFromFile:#"images/image.png"] won't.
As a side note I must say that I don't use groups, I fisically create the folders in the filesystem and then I add them to xcode.
Is there anything special I must do to load an assets that is not directly contained by Resources directory?.
Thanks in advance.
Since there is no link between the tree structure (groups, etc) diplayed in the Project Tree and the actual position of the files, you have to be carefull about how you move files around on your disk. You should put the files at their right place on your disk, THEN drop them on your project tree in XCode. After that you shouldn't move them again, otherwise Xcode will keep the old path to them, and the logical reference to the file is lost (in Xcode).
And be sure to uncheck the checkbox on the top so that Xcode will only create a reference to your files without copying them himself.
you could tried getting the file path manually from NSBundle:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"image" ofType:#"png" inDirectory:#"images"];
Now that you have the file path, im not sure how to set the image to the sprite.. Maybe you could try through CGImage...
Hope this helps
Related
We have a Cocoa Mac OS X application in which we want to bundle around 500 images. Each image is around 10kb so size isn't a problem.
These images are not exactly resources in the app, they are sample images.
Basically, we have simple button that would let the user copy these images to a directory.
The solution also needs to be "dump in, dump out" -- so we don't want to store individual image file names somewhere in our application; we just want to have a directory of images that can be copied.
How do I package these into my application?
The question turns into: How do I make a directory resource containing the images.
In our case everything gets flattened into the MyApp.app/Contents/Resources and this approach would require us to put image names in the app so that we can copy those.
Put the images into a folder. Drag the folder into your project in Xcode. In the resulting dialog, make sure you copy, make sure you create a folder reference, and make sure you add to your app target. Done. Now the folder is part of your app bundle and you can refer to it from your code without knowing anything about its contents.
The folder /Library/Application Support is for support files that, if deleted, would not affect the execution of an application. I would suggest this is ideal for your product's sample images.
As Apple's documentation states for Application Support:
Use this directory to store all app data files except those associated with the user’s documents. For example, you might use this directory to store app-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the app. An app might use this directory to store a modifiable copy of resources contained initially in the app’s bundle.
So, use pkgbuild / productbuild to install them to /Library/Application Support/<ProductName>/
Because size is not an issue, you can just put all your sample images in separate Asset Catalog file.
Design team provide a folder with all the images required for a project.
I've create xcassets for the icon and splash files, and for some images who require slicing, etc
I've notices that all the image in xcassets have been duplicate in the xcassets folder.
My question:
From xcassets, can I link to image, instead of having xcode
duplicate it?
If link not possible, what are the best way to work with design
team?
Do you thing that, at compile time, xcode will insert just one copy
of the image?
Thanks for your infos
The purpose of xcassets is to consolidate all of your project assets into a nice bundle. I tend to split into multiple xcassets for larger projects. After you pop everything to xcassets, you can get rid of other asset instances from your project.
In compile time, only the files selected in the "add to target" field will be copied over.
Just stick all your files into xcassets, don't add them anywhere else.
yes ofcourse there is one tool for your problem's solution
AVXCassets Generator
Hope you will like it
I implemented the document provider app extension feature with my own
ios app. The problem is the app extension was not able to access the
containing app images/assets or the containing apps resource data.
Does any one knows how to achieve it?.
The extension has its own target in your Xcode project. In order to access resources in the extension you also need to add them to that target (in the File Inspector also check your extension target in the Target Membership section). Just be aware that those resources also get copied into the extension bundle, which increases your overall app size.
Sidenote: In my extension I didn't add my default image asset catalogue (Images.xcassets) to the extension, but was still able to access the containing images. Maybe that's an exception.
UPDATE
If you are supporting iOS 8 and up, you can create a framework to share among your app and it's extensions, and embed resources, strings, etc. inside of it. Make sure to use the [UIImage imageNamed:inBundle:compatibleWithTraitCollection:] and NSLocalizedStringFromTableInBundle methods, passing in the bundle that is your framework.
PREVIOUS ANSWER
Given that extensions are (and hopefully always will be) in a sub-folder of the main app at /Plugins/PluginName and have permissions to access files just like the main app, you can do the following (and I do in some of my apps on the store):
// image
UIImage* image = [UIImage imageNamed:#"../../image_name.png"]
// data
NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:#"../../file.json"];
NSData* data = [NSData dataWithContentsOfFile:path];
This will save you a lot of space, especially if your extension uses a lot of images.
So I'm used to this kind of sorting my source files, but I can't seem to be able to find a solution to this problem in Xpages. It would be great if I can store my images like for example: UI images in "ui", layout images in "layout" and so on... Is this possible? Or maybe some kind of workaround?
Thank you!
In image resources, you can also use "virtual folders" to organize the image files.
E.g.
If you have a header image named "header.png". Rename to "layout\header.png".
When you reference this image from the web browser, the path will be:
http://somedomain.com/path/to/db.nsf/layout/header.png
In Package Explorer (or Eclipse Navigator), locate the WebContent folder. This is treated as the "root" of the NSF when an XPage is accessed. If your images are already stored on your hard drive in the folder structure you want to create, you can literally just drag the top-level folder to WebContent, and it'll preserve the exact same structure. You can also manually add folders to WebContent (or any subfolder) using the context menu.
Use the Eclipse Navigator view (add it to your perspective) - there you should be able to create a folder in the images. What works definitely is to use webDAV for design files
I have a path problem with UIImage.FromFile() method. My solution folder has 3 projects and the main UI project has an Images folder in it. I put all my project images in this folder and I have code like this:
UIImage myImg = UIImage.FromFile("Images/someImage.png");
I have already examined this and all these topics..
I set images property of build to "content" and etc..
Can you help me:
step by step adding an image to a specific project folder and use it dynamically
how to use NSBundle and why we have to use this?
Generally, if you have right clicked on the file, gone to it's properties and marked it as Content then the following will work:
UIImage myImg = UIImage.FromFile(#"Images/someImage.png");
The very first question you linked to has the solution - you need to use Unix style paths ("/"), not DOS/Windows paths ("\").
You should also carefully check the casing of your paths - the emulator is more forgiving of incorrect case than the actual device is.
Finally, look inside of your .app bundle to verify that the image files are really where you think they are, relative to the root of the bundle.