Access Photo Library in cocos2d - iphone

I am creating a game using cocos2d.
Now what I want is I need to insert the image from Photo Library to my application. Can you please tell how can we access Photo Library through cocos2d?
Thanks in ADVANCE...

You should be able to access the users Photo Library in the normal fashion. As far as actually using the selected photo, is a different question. ;-)

Not sure if this is what you mean but...
To use an image in your application you put the image file in your resources folder in xcode. Then you can reference it by name to use it for your sprites or anything else that will use a file. This goes for other types of files that your application will use too (like data files, plists, etc).
If you put an icon file in your resources folder in xcode and name it icon.png then that will be the icon that will appear for the user to select to run your application on the iphone/ipod/ipad.
Same goes if you put another file in the resources folder and name it default.png then it will show up as the splash screen that appears while your application is being loaded.
Note: If you are working with a template it will probably already have canned files with these names. Just remove them from the resource folder in xcode and add the new ones. To add the files to your project, drag them into the resource folder within xcode and select the check box for: "Copy items into destination group's folder (if needed)", as well as, make sure in add targets section only the check box for your application name is checked and the radio button "Recursively create groups for any added folders" is selected. This will copy the file(s) into your project directory and they will also appear in the resources folder in xcode. You can then click on them in xcode to see that they are correct.

Related

How to change location of iPhone app icon?

Okay, I am a noob. It must be simple but I stuck here.
I do rigth-click and choose 'select file'.
After I choose the file the dialogue appears:
I want to keep my icons not in the root directory. But I can't figure out how to do this. I tried different ways, even create project from scratch...
Please help.
When you bring image assets into Xcode they will all be in your application bundle's root directory at run time.
It appears that you've added a file named "icon#2x.png" to your project at one time already. Go to the project's summary page in Xcode click Build Phases and then expand the section titled Copy Bundle Resources. There you'll find the reference to the resources that will be copied to your bundle at run time.
More on bundle structures here:
https://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
Anyway, the way I've done this in the past is to:
Remove the existing image duplicate from Xcode and from the folder structure in Finder.
Add a new folder in Finder call it "/AppIcons" (or whatever).
Copy all the app icons to that folder in Finder.
Drag the "/AppIcon" folder into your XCode project. I typically put images in an "/Images" subdirectory in the Xcode project. Again you can put it wherever you'd like.
In Xcode on the project summary panel, add your app icons from the folder "/AppIcons" by dragging / dropping or by right clicking and adding them as separate files.
Alternatively in the past when I've had problems with this sometimes Xcode will copy the app icons to the root project directory. If that happens, I make sure that I have the "/AppIcons" folder structure on disc (in Finder) and in my Xcode project. I add the app icons to the project, then move them to /AppIcons in Finder, and re-reference them all over again.
Your Copy Bundle Resources should then have the proper file reference. Note that my apps icons go in "/Images/AppIcons"
Good luck!
I would add the image files to your project with the name icon#2x.png. To do this right click where you want to add the files in xcode and click add file/s. Then search for your image and add them using the dialogue that pops up. - there is a check box so that you can either copy them to the projects destination folder which will copy them into you project folder or leave it unchecked (inadvisable) which would reference it's current location on your HDD. Make sure the file doesn't already exist in the project before doing this!
EDIT:
Sorry I forgot to mention then drag and drop the file from within xcode onto the image location box.
In XCode 4 (I'm using 4.6.2) you will get this confusing message if you've just moved the target's info.plist file, but not corrected the location at the top of the summary panel. Fix this and the icons will reappear, assuming they are added to the project, or if not you should now be able to drag them in without xcode insisting on making extra copies.
This tends to happen when you're starting a project and sorting out the mess of default file locations that xcode gives you. I like my project structure to be 99% the same as the file system structure.
This is an easy fix. If the image you want as your App Icon resides outside of the root of your project, when you get that dialog just click "Yes", and then click delete on the newly created file in the root, and "Move to Trash".
The reference is still there and works without a hitch, since the file will still be in the root at runtime

Changing app target name makes PNGs disappear?

Trying to change the name of the app from the development name to the production name, I renamed the target as a first stab. The PNGs in the app disappeared. I then changed the target name back to the original name and re-built, but now the PNGs are still missing.
I'm looking at step-by-step guides on project/app name changing, but I don't want to proceed until I'm unable to undo whatever this did.
Does anyone know why the images would now be missing? Even after I changed the name back?
I'm assuming there is some path based on the target name and that changing the target name triggered other changes not reversed by simply changing the target again?
Many thanks
why not just use Product Name under Target -> Build Options. So you don't have to change the target name! :)
Type in the name of your project in the finder, and double click on the project folder. Inside that folder (it may be in a folder inside that folder, like resources or something but on my computer its all in the project folder) look for .png images. These images are the images that are in your project. Delete every image inside here, or just move it somewhere else. If your app has the .png files inside the project folder, but the files are in your resources folder, you won't be able to put in the same image in your resources folder because your project (your app) says its already there, even though its just sitting there and your not using it...
So delete all the .pngs inside your project folder, then open up the app with xcode and drag the image files you need into the resources folder. Hope this helped.
Each file in a project can be included in a target, when you changed the target name, its possible that png files lost association to the target. right click on the folder which has the png files, and click on get info, there you will be able to select which targets this folder is included in, mark the check box for your intended target, and the files will be included again in your target.

How to add bundles and resources like images in that bundle in iPhone

I created bundle using i-phone-OS->resources->setting but I am unable to add images to this bundle. I tried dragging images folder or by adding existing to folder but nothing works.
Thanks in advance
The Settings.bundle is added as a folder/bundle reference and not as a group.
Thus you won't be able to easily add some content to it right from the Groups & Files panel in Xcode unfortunately. Instead, go in the Finder, right-click (or ctrl-click) on this Settings.bundle and select "Show Package Contents" then drag & drop files in there. You will then find the added files back in Xcode.
I also find this kinda anoying in Xcode3 that we can't add files to '.bundle' folders/bundles directly from Xcode3 :( But AFAIK there is no other solution
One your file has been added to the '.bundle', you can edit them directly from Xcode. (Going thru the Finder is only necessary for adding new files to it)

iPhone Interface Builder - Moved resources to sub-directory, now IB can't see them!

I had a bunch of images in my Xcode project. They were originally added without choosing "Create Folder References for any added folders". So I removed the references and re-added as per these instructions Include a resource directory hierarchy into app bundle
Unfortunately, Interface Builder will not display any of the images inside that directory. On the project tree the directory comes up with a blue icon and all the files are there!
The file names show in the IB Inspector (i.e. under the 'Image' property), but I get missing image icons for everything located in that directory.
Any ideas how to get the images showing again?
Problem solved! Turns out that blue folder references are fine, but IB will not read them!
For anyone else who cares to know, if you have the following:
/iphone-project-dir/images/pic.png
Once you've added them in a blue folder in Xcode (as detailed in link above), you can refer to them in IB as follows:
images/pic.png
In the XIB's XML it will look something like this
<string key="NSResourceName">images/pic.png</string>
Simple! The only drawback is Interface Builder's WYSIWYG preview does not process these paths!
I found the answer here http://www.iphonedevsdk.com/forum/iphone-sdk-development/6457-xcode-folder-directories.html
If you like to have your images structured in your SCM and under XCode but really doesn't mind that all images will be placed in one directory once building the final .ipa package, here is what you need to do:
Create a directory called e.g. "Images" in your root folder
Place all your images into this folder
Add a new group from within XCode and call this "Images" too
Right-click this group and choose "Add Files to ..."
Select all your files and uncheck "Copy items into destination group's folder" because they are already in there
Make sure to select your right targets
From Interface Builder you are now able to pick your images without prefixing it with the folder name and you will see a preview of your images within Interface Builder.
Gives me both my IB preview and a neat folder structure when designing my app.
Copy Images folder to your project folder.
Add this folder to project. In "Choose options for adding these files" dialog, you must check "Create groups".
"Copy items if needed" you can leave checked.
Make sure to select your right targets
Finish

Add image to targets folder by code

i want to add a image to the iphone application Targets-Copy Bundle Resource folder by using code,can make it?any suggestion
Do you want to add images to your built application, so they're available at runtime? In this case, just drag them to your Project tree and make sure your target is checked in the Add dialog. If they're already in your project, but aren't currently in the Copy Bundle Resources, you can drag them there from the file tree.