Loading resources from folders contained in Resources folder.
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 una开发者_Python百科ble 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
精彩评论