cocos2d-iphone  2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
CCFileUtils Class Reference

#import <CCFileUtils.h>

List of all members.

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

Detailed Description

Helper class to handle file operations


Member Function Documentation

Calling this method will populate the searchResolutionsOrder property depending on the current device.

Since:
v2.1
- (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"

Since:
v2.1
- (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"

Since:
v2.1
- (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")

Since:
v2.1
- (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.

Since:
v2.1
- (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.

Since:
v1.1
- (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.

Since:
v2.0
- (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.

Since:
v1.1

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

Since:
v0.99.5
- (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.

Since:
v2.0
- (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.

Since:
v1.1
- (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.

Since:
v1.1

returns the shared file utils instance


Property Documentation

- (NSBundle*) bundle [read, write, retain]

NSBundle used by CCFileUtils. By default it uses [NSBundle mainBundle].

Since:
v2.0
- (NSMutableDictionary*) directoriesDict [read, write, copy]

Dictionary that contians the search directories for the different devices. Default values:

  • iPhone: "resources-iphone"
  • iPhone HD: "resources-hd"
  • iPhone5 : "resources-wide"
  • iPhone5 HD: "resources-widehd"
  • iPad: "resources-ipad"
  • iPad HD: "resources-ipadhd"
  • Mac: "resources-mac"
  • Mac HD: "resources-machd"

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.

Since:
v2.1
- (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.

Since:
v2.0
- (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;

Since:
v2.1
- (int) searchMode [read, write, assign]

It determines how the "resolution resources" are to be searched. Possible values:

  • kCCFileUtilsSearchSuffix: It will search for resources by appending suffixes like "-hd", "-ipad", etc...
  • kCCFileUtilsSearchDirectory: It will search the resoureces in subdirectories like "resources-hd", "resources-ipad", etc...

Default: kCCFileUtilsSearchSuffix

Since:
v2.1
- (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.

Since:
v2.1
- (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:

  • On iPad HD: iPad HD resources, iPad resources, resources not associated with any device
  • On iPad: iPad resources, resources not associated with any device
  • On iPhone 5 HD: iPhone 5 HD resources, iPhone HD resouces, iPhone 5 resources, iPhone resources, resources not associated with any device
  • On iPhone HD: iPhone HD resources, iPhone resouces, resources not associated with any device
  • On iPhone: iPhone resources, resources not associated with any device
  • On Mac HD: Mac HD resources, Mac resources, resources not associated with any device
    • On Mac: Mac resources, resources not associated with any device

If the property "enableiPhoneResourcesOniPad" is enabled, it will also search for iPhone resources if you are in an iPad.

Since:
v2.1
- (NSMutableDictionary*) suffixesDict [read, write, copy]

Dictionary that contians the suffix for the different devices. Default values:

  • iPhone: ""
  • iPhone HD: "-hd"
  • iPhone5 : "-wide"
  • iPhone5 HD: "-widehd"
  • iPad: "-ipad"
  • iPad HD: "-ipadhd"
  • Mac: ""
  • Mac HD: "-machd"

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.

Since:
v2.1

The documentation for this class was generated from the following file: