![]() |
cocos2d-iphone
2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
|
#import <CCFileUtils.h>
Public Member Functions | |
(void) | - setiPhoneRetinaDisplaySuffix: |
(void) | - setiPadSuffix: |
(void) | - setiPadRetinaDisplaySuffix: |
(void) | - purgeCachedEntries |
(void) | - buildSearchResolutionsOrder |
(NSString *) | - fullPathFromRelativePathIgnoringResolutions: |
(NSString *) | - fullPathForFilename: |
(NSString *) | - fullPathForFilename:resolutionType: |
(NSString *) | - fullPathForFilenameIgnoringResolutions: |
(void) | - loadFilenameLookupDictionaryFromFile: |
(NSString *) | - standarizePath: |
(void) | - setEnableFallbackSuffixes: |
(NSString *) | - fullPathFromRelativePath: |
(NSString *) | - fullPathFromRelativePath:resolutionType: |
(NSString *) | - removeSuffixFromFile: |
(BOOL) | - iPhoneRetinaDisplayFileExistsAtPath: |
(BOOL) | - iPadFileExistsAtPath: |
(BOOL) | - iPadRetinaDisplayFileExistsAtPath: |
Static Public Member Functions | |
(CCFileUtils *) | + sharedFileUtils |
(void) | + setRetinaDisplaySuffix: |
Protected Attributes | |
NSFileManager * | _fileManager |
NSBundle * | _bundle |
NSMutableDictionary * | _fullPathCache |
NSMutableDictionary * | _fullPathNoResolutionsCache |
NSMutableDictionary * | _removeSuffixCache |
NSMutableDictionary * | _directoriesDict |
NSMutableDictionary * | _suffixesDict |
NSMutableDictionary * | _filenameLookup |
NSMutableArray * | _searchResolutionsOrder |
NSMutableArray * | _searchPath |
int | _searchMode |
BOOL | _enableiPhoneResourcesOniPad |
Properties | |
NSBundle * | bundle |
NSFileManager * | fileManager |
BOOL | enableiPhoneResourcesOniPad |
NSMutableDictionary * | directoriesDict |
NSMutableDictionary * | suffixesDict |
NSArray * | searchResolutionsOrder |
NSArray * | searchPath |
int | searchMode |
NSMutableDictionary * | filenameLookup |
Helper class to handle file operations
- (void) buildSearchResolutionsOrder |
Calling this method will populate the searchResolutionsOrder property depending on the current device.
- (NSString*) fullPathForFilename: | (NSString *) | filename |
Returns the fullpath for a given filename.
First it will try to get a new filename from the "filenameLookup" dictionary. If a new filename can't be found on the dictionary, it will use the original filename. Then it will try obtain the full path of the filename using the CCFileUtils search rules: resolutions, and search paths
If in iPad mode, and an iPad file is found, it will return that path. If in iPhoneRetinaDisplay mode, and a RetinaDisplay file is found, it will return that path. But if it is not found, it will try load an iPhone Non-RetinaDisplay file.
If the filename can't be found on the file system, it will return nil.
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable, you might need to load differerent resources for a given file in the different platforms.
Examples:
In iPad mode: "image.png" -> "image.pvr" -> "/full/path/image-ipad.pvr" (in case the -ipad file exists) In Android: "image.png" -> "image.png" -> "/full/path/image.png"
- (NSString*) fullPathForFilename: | (NSString *) | filename | |
resolutionType: | (ccResolutionType *) | resolutionType | |
Returns the fullpath for a given filename.
First it will try to get a new filename from the "filenameLookup" dictionary. If a new filename can't be found on the dictionary, it will use the original filename. Then it will try obtain the full path of the filename using the CCFileUtils search rules: resolutions, and search paths
If in iPad mode, and an iPad file is found, it will return that path. If in iPhoneRetinaDisplay mode, and a RetinaDisplay file is found, it will return that path. But if it is not found, it will try load an iPhone Non-RetinaDisplay file.
If the filename can't be found on the file system, it will return nil.
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable, you might need to load differerent resources for a given file in the different platforms.
Examples:
In iPad mode: "image.png" -> "image.pvr" -> "/full/path/image-ipad.pvr" (in case the -ipad file exists) In Android: "image.png" -> "image.png" -> "/full/path/image.png"
- (NSString*) fullPathForFilenameIgnoringResolutions: | (NSString *) | key |
Returns the fullpath for a given filename, without taking into account device resolution.
It will try to get a new filename from the "filenameLookup" dictionary. If a new filename can't be found on the dictionary, it will use the original filename.
Once it gets the filename, it will try to get the fullpath for the filename, using the "searchPath", but it won't use any resolution search rules. If the file can't be found, it will return nil.
Useful for loading music files, shaders, "data" and other files that are not related to the screen resolution of the device.
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable, you might need to load differerent resources for a given file in the different platforms.
Examples:
On iOS: "sound.wav" -> "sound.caf" -> "/full/path/sound.caf" (in case the key dictionary says that "sound.wav" should be converted to "sound.caf") On Android: "sound.wav" -> "sound.wav" -> "/full/path/sound.caf" (in case the key dictionary says that "sound.wav" should be converted to "sound.caf")
- (NSString*) fullPathFromRelativePath: | (NSString *) | relPath |
Returns the fullpath of an filename.
If in iPhoneRetinaDisplay mode, and a RetinaDisplay file is found, it will return that path. If in iPad mode, and an iPad file is found, it will return that path.
If the filename can't be found, it will return "relPath" instead of nil.
Examples:
In iPad mode: "image.png" -> "/full/path/image-ipad.png" (in case the -ipad file exists) In iPhone RetinaDisplay mode: "image.png" -> "/full/path/image-hd.png" (in case the -hd file exists) In iPad RetinaDisplay mode: "image.png" -> "/full/path/image-ipadhd.png" (in case the -ipadhd file exists)
- (NSString*) fullPathFromRelativePath: | (NSString *) | relPath | |
resolutionType: | (ccResolutionType *) | resolutionType | |
Returns the fullpath of an filename. It will try to get the correct file for the current screen resolution. Useful for loading images and other assets that are related for the screen resolution.
If in iPad mode, and an iPad file is found, it will return that path. If in iPhoneRetinaDisplay mode, and a RetinaDisplay file is found, it will return that path. But if it is not found, it will try load an iPhone Non-RetinaDisplay file.
If the filename can't be found, it will return "relPath" instead of nil.
Examples:
In iPad mode: "image.png" -> "/full/path/image-ipad.png" (in case the -ipad file exists) In iPhone RetinaDisplay mode: "image.png" -> "/full/path/image-hd.png" (in case the -hd file exists) In iPad RetinaDisplay mode: "image.png" -> "/full/path/image-ipadhd.png" (in case the -ipadhd file exists)
- (NSString*) fullPathFromRelativePathIgnoringResolutions: | (NSString *) | relPath |
Returns the fullpath of an filename without taking into account the screen resolution suffixes or directories.
It will use the "searchPath" though. If the file can't be found, it will return nil.
Useful for loading music files, shaders, "data" and other files that are not related to the screen resolution of the device.
- (BOOL) iPadFileExistsAtPath: | (NSString *) | filename |
Returns whether or not a given filename exists with the iPad suffix. Only available on iOS. Not supported on OS X.
- (BOOL) iPadRetinaDisplayFileExistsAtPath: | (NSString *) | filename |
Returns whether or not a given filename exists with the iPad RetinaDisplay suffix. Only available on iOS. Not supported on OS X.
- (BOOL) iPhoneRetinaDisplayFileExistsAtPath: | (NSString *) | filename |
Returns whether or not a given path exists with the iPhone RetinaDisplay suffix. Only available on iOS. Not supported on OS X.
- (void) purgeCachedEntries |
Purge cached entries. Will be called automatically by the Director when a memory warning is received
- (NSString *) removeSuffixFromFile: | (NSString *) | path |
removes the suffix from a path On iPhone RetinaDisplay it will remove the -hd suffix On iPad it will remove the -ipad suffix On iPad RetinaDisplay it will remove the -ipadhd suffix
- (void) setEnableFallbackSuffixes: | (BOOL) | enableFallbackSuffixes |
- (void) setiPadRetinaDisplaySuffix: | (NSString *) | iPadRetinaDisplaySuffix |
Sets the iPad Retina Display suffixes to load resources. By default it is "-ipadhd", "-ipad", "-hd", "", in that order. Only valid on iOS. Not valid for OS X.
- (void) setiPadSuffix: | (NSString *) | iPadSuffix |
The iPad suffixes to load resources. By default it is "-ipad", "-hd", "", in that order. Only valid on iOS. Not valid for OS X.
- (void) setiPhoneRetinaDisplaySuffix: | (NSString *) | iPhoneRetinaDisplaySuffix |
The iPhone RetinaDisplay suffixes to load resources. By default it is "-hd" and "" in that order. Only valid on iOS. Not valid for OS X.
returns the shared file utils instance
- (NSBundle*) bundle [read, write, retain] |
NSBundle used by CCFileUtils. By default it uses [NSBundle mainBundle].
- (NSMutableDictionary*) directoriesDict [read, write, copy] |
Dictionary that contians the search directories for the different devices. Default values:
If "search in directories" is enabled (disabled by default), it will try to get the resources from the directories according to the order of "searchResolutionsOrder" array.
- (BOOL) enableiPhoneResourcesOniPad [read, write, assign] |
Whether of not the fallback suffixes is enabled. When enabled it will try to search for the following suffixes in the following order until one is found: On iPad HD : iPad HD, iPad, iPhone HD, Resources without resolution On iPad : iPad, iPhone HD, Resources without resolution On iPhone HD: iPhone HD, Resources without resolution On Mac HD : Mac HD, Mac, Resources without resolution On Mac : Mac, Resources without resolution
By default this functionality is off;
- (NSFileManager*) fileManager [read, write, retain] |
NSFileManager used by CCFileUtils. By default it uses its own instance.
- (NSMutableDictionary*) filenameLookup [read, write, copy] |
Dictionary used to lookup filenames based on a key. It is used internally by the following methods:
-(NSString*) fullPathForFilename:key resolutionType:(ccResolutionType*)resolutionType; -(NSString*) fullPathForFilenameIgnoringResolutions:key;
- (int) searchMode [read, write, assign] |
It determines how the "resolution resources" are to be searched. Possible values:
Default: kCCFileUtilsSearchSuffix
- (NSArray*) searchPath [read, write, copy] |
Array of search paths. You can use this array to modify the search path of the resources. If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
By default it is an array with only the "" (empty string) element.
- (NSArray*) searchResolutionsOrder [read, write, copy] |
Array that contains the search order of the resources based for the device. By default it will try to load resources in the following order until one is found:
If the property "enableiPhoneResourcesOniPad" is enabled, it will also search for iPhone resources if you are in an iPad.
- (NSMutableDictionary*) suffixesDict [read, write, copy] |
Dictionary that contians the suffix for the different devices. Default values:
If "search with suffixes" is enabled (enabled by default), it will try to get the resources by appending the suffixes according to the order of "searchResolutionsOrder" array.