Inherits from NSObject
Declared in CCTextureCache.h

Overview

Singleton that handles the loading of textures Once the texture is loaded, the next time it will return a reference of the previously loaded texture reducing GPU & CPU memory

Tasks

Other Methods

  • + sharedTextureCache

    Retruns ths shared instance of the cache

  • + purgeSharedTextureCache

    purges the cache. It releases the retained instance.

  • – addImage:

    Returns a Texture2D object given an file image If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. It will use the filename as a key. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

  • – addImageAsync:target:selector:

    Asynchronously, load a texture2d from a file. If the file image was previously loaded, it will use it. Otherwise it will load a texture in a new thread, and when the image is loaded, the callback will be called with the Texture2D as a parameter. The callback will be called in the cocos2d thread, so it is safe to create any cocos2d object from the callback. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

  • – addImageAsync:withBlock:

    Asynchronously, load a texture2d from a file. If the file image was previously loaded, it will use it. Otherwise it will load a texture in a new thread, and when the image is loaded, the block will be called. The callback will be called in the cocos2d thread, so it is safe to create any cocos2d object from the callback. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

  • – addCGImage:forKey:

    Returns a Texture2D object given an CGImageRef image If the image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previously loaded image The “key” parameter will be used as the “key” for the cache. If “key” is nil, then a new texture will be created each time.

  • – textureForKey:

    Returns an already created texture. Returns nil if the texture doesn’t exist.

  • – removeAllTextures

    Purges the dictionary of loaded textures. Call this method if you receive the “Memory Warning” In the short term: it will free some resources preventing your app from being killed In the medium term: it will allocate more resources In the long term: it will be the same

  • – removeUnusedTextures

    Removes unused textures Textures that have a retain count of 1 will be deleted It is convenient to call this method after when starting a new Scene

  • – removeTexture:

    Deletes a texture from the cache given a texture

  • – removeTextureForKey:

    Deletes a texture from the cache given a its key name

Other Methods

  • – addPVRTCImage:bpp:hasAlpha:width:

    Returns a Texture2D object given an PVRTC RAW filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previosly loaded image

  • – addPVRTCImage:

    Returns a Texture2D object given an PVRTC filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previosly loaded image

PVRSupport Methods

  • – addPVRImage:

    Returns a Texture2D object given an PVR filename. If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previously loaded image

Debug Methods

  • – dumpCachedTextureInfo

    Output to CCLOG the current contents of this CCTextureCache This will attempt to calculate the size of each texture, and the total texture memory in use

iTraceurDynamicTiles Methods

Class Methods

purgeSharedTextureCache

purges the cache. It releases the retained instance.

+ (void)purgeSharedTextureCache

Availability

Declared In

CCTextureCache.h

sharedTextureCache

Retruns ths shared instance of the cache

+ (CCTextureCache *)sharedTextureCache

Declared In

CCTextureCache.h

Instance Methods

addCGImage:forKey:

Returns a Texture2D object given an CGImageRef image If the image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previously loaded image The “key” parameter will be used as the “key” for the cache. If “key” is nil, then a new texture will be created each time.

- (CCTexture2D *)addCGImage:(CGImageRef)image forKey:(NSString *)key

Availability

Declared In

CCTextureCache.h

addImage:

Returns a Texture2D object given an file image If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. It will use the filename as a key. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

- (CCTexture2D *)addImage:(NSString *)fileimage

Declared In

CCTextureCache.h

addImageAsync:target:selector:

Asynchronously, load a texture2d from a file. If the file image was previously loaded, it will use it. Otherwise it will load a texture in a new thread, and when the image is loaded, the callback will be called with the Texture2D as a parameter. The callback will be called in the cocos2d thread, so it is safe to create any cocos2d object from the callback. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

- (void)addImageAsync:(NSString *)filename target:(id)target selector:(SEL)selector

Availability

Declared In

CCTextureCache.h

addImageAsync:withBlock:

Asynchronously, load a texture2d from a file. If the file image was previously loaded, it will use it. Otherwise it will load a texture in a new thread, and when the image is loaded, the block will be called. The callback will be called in the cocos2d thread, so it is safe to create any cocos2d object from the callback. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

- (void)addImageAsync:(NSString *)filename withBlock:(void ( ^ ) ( CCTexture2D *tex ))block

Availability

Declared In

CCTextureCache.h

addImageFromAnotherThreadWithName:target:selector:

addPVRImage:

Returns a Texture2D object given an PVR filename. If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previously loaded image

- (CCTexture2D *)addPVRImage:(NSString *)filename

Declared In

CCTextureCache.h

addPVRTCImage:

Returns a Texture2D object given an PVRTC filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previosly loaded image

- (CCTexture2D *)addPVRTCImage:(NSString *)filename

Declared In

CCTextureCache.h

addPVRTCImage:bpp:hasAlpha:width:

Returns a Texture2D object given an PVRTC RAW filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. Otherwise it will return a reference of a previosly loaded image

- (CCTexture2D *)addPVRTCImage:(NSString *)fileimage bpp:(int)bpp hasAlpha:(BOOL)alpha width:(int)w

Discussion

It can only load square images: width == height, and it must be a power of 2 (128,256,512…) bpp can only be 2 or 4. 2 means more compression but lower quality. hasAlpha: whether or not the image contains alpha channel

Declared In

CCTextureCache.h

dumpCachedTextureInfo

Output to CCLOG the current contents of this CCTextureCache This will attempt to calculate the size of each texture, and the total texture memory in use

- (void)dumpCachedTextureInfo

Availability

Declared In

CCTextureCache.h

removeAllTextures

Purges the dictionary of loaded textures. Call this method if you receive the “Memory Warning” In the short term: it will free some resources preventing your app from being killed In the medium term: it will allocate more resources In the long term: it will be the same

- (void)removeAllTextures

Declared In

CCTextureCache.h

removeTexture:

Deletes a texture from the cache given a texture

- (void)removeTexture:(CCTexture2D *)tex

Declared In

CCTextureCache.h

removeTextureForKey:

Deletes a texture from the cache given a its key name

- (void)removeTextureForKey:(NSString *)textureKeyName

Availability

Declared In

CCTextureCache.h

removeUnusedTextures

Removes unused textures Textures that have a retain count of 1 will be deleted It is convenient to call this method after when starting a new Scene

- (void)removeUnusedTextures

Availability

Declared In

CCTextureCache.h

textureForKey:

Returns an already created texture. Returns nil if the texture doesn’t exist.

- (CCTexture2D *)textureForKey:(NSString *)key

Availability

Declared In

CCTextureCache.h