Inherits from PXLoader : NSObject
Declared in PXTextureLoader.h
PXTextureLoader.m

Overview

A PXTextureLoader loads images synchronously and creates PXTextureData objects.

Once instantiated with a valid file path, objects of the PXTextureLoader class hold a copy of the loaded data and can be used to generate PXTextureData instances.

For most uses generating more than one PXTextureData object is unnecessary as a single PXTextureData may be shared among many PXTexture display objects.

Once a PXTextureData instance has been created, the PXTextureLoader instance may be safely deallocated by calling release. Since PXTextureLoader keeps a copy of the loaded data, it is advisable to release all unneeded instances as soon as a PXTextureData object has been created in order to free up memory.

The following image formats are supported natively:

  • .tiff and .tif
  • .jpeg and .jpg
  • .bmp and .BMPf
  • .ico
  • .cur
  • .xmb
  • .png (uses libpng)
  • .pvr
  • .pvrtc

Example: The following code sample loads a png file and renders it to the screen:

// Create a loader object to load and parse the png from the application
// bundle.
PXTextureLoader *loader = [[PXTextureLoader alloc] initWithContentsOfFile:@"logo.png"];
// Turn the loaded data to an OpenGL texture
PXTextureData *textureData = [loader newTextureData];
// The loader is no longer needed
[loader release];
loader = nil;

// Create a PXTexture display object to render the texture data to the
// screen.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[textureData release];
textureData = nil;

// Add the display object to the display list so it can be rendered
[self addChild:texture];
[texture release];

Tasks

Other Methods

  •   modifier

    A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

    property
  • – initWithContentsOfFile:modifier:

    Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file could not be found, or the image format isn’t supported.

  • – initWithContentsOfURL:modifier:

    Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

  • – newTextureData

    Creates a new PXTextureData object containing a copy of the loaded image data. Note that all returned copies must be released by the caller.

  • – setContentScaleFactor:

    Use this method to change the automatic contentScaleFactor adjustment that happens when an image is loaded in. It is not advised to use this method unless you know what you’re doing.

  • + resolvePathForImageFile:

    Given an image name (with an extension or not), this method tries to find a valid path for it. If it doesn’t find an exact match to the fileName, it tries to find siblings with the same name and a supported extension. Returns nil if nothing was found.

  • + textureLoaderWithContentsOfFile:modifier:

    Creates a PXTextureLoader instance containing the loaded image data. Returns nil if the file could not be found, or the image format isn’t supported.

  • + textureLoaderWithContentsOfURL:

    Creates a PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

  • + textureLoaderWithContentsOfURL:modifier:

    Creates a PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

Other Methods

  • – initWithContentsOfFile:

    Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file could not be found, or the image format isn’t supported.

Other Methods

  • – initWithContentsOfURL:

    Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

Properties

modifier

A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

@property (nonatomic, retain) id<PXTextureModifier> modifier

Discussion

Default: nil

Declared In

PXTextureLoader.h

Class Methods

resolvePathForImageFile:

Given an image name (with an extension or not), this method tries to find a valid path for it. If it doesn’t find an exact match to the fileName, it tries to find siblings with the same name and a supported extension. Returns nil if nothing was found.

+ (NSString *)resolvePathForImageFile:(NSString *)fileName

Declared In

PXTextureLoader.m

textureLoaderWithContentsOfFile:modifier:

Creates a PXTextureLoader instance containing the loaded image data. Returns nil if the file could not be found, or the image format isn’t supported.

+ (PXTextureLoader *)textureLoaderWithContentsOfFile:(NSString *)path modifier:(id<PXTextureModifier>)modifier

Parameters

path

The path of the image file to load. The file path may be absolute or relative to the application bundle. The path may also omit the file extension, and Pixelwave will try to find a valid image with that name.

modifier

A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

Return Value

The resulting, autoreleased, PXTextureLoader object.

Example:

PXTextureLoader *textureLoader = [PXTextureLoader textureLoaderWithContentsOfFile:@"image.png"
                                                                         modifier:[PXTextureModifiers textureModifierToPixelFormat:PXTextureDataPixelFormat_RGBA5551]];
// This texture data will be stored as a 5551 texture; as in, 5 bytes for
// red, green, and blue and only 1 byte for alpha.
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];

Declared In

PXTextureLoader.m

textureLoaderWithContentsOfURL:

Creates a PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

+ (PXTextureLoader *)textureLoaderWithContentsOfURL:(NSURL *)url

Parameters

url

The url of the image to load.

Return Value

The resulting, autoreleased, PXTextureLoader object.

Example:

PXTextureLoader *textureLoader = [PXTextureLoader textureLoaderWithContentsOfURL:[NSURL URLWithString:@"www.myWebsite.com/image.png"]];
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];

Declared In

PXTextureLoader.m

textureLoaderWithContentsOfURL:modifier:

Creates a PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

+ (PXTextureLoader *)textureLoaderWithContentsOfURL:(NSURL *)url modifier:(id<PXTextureModifier>)modifier

Parameters

url

The url of the image to load.

modifier

A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

Return Value

The resulting, autoreleased, PXTextureLoader object.

Example:

PXTextureLoader *textureLoader = [PXTextureLoader textureLoaderWithContentsOfURL:[NSURL URLWithString:@"www.myWebsite.com/image.png"]
                                                                        modifier:[PXTextureModifiers textureModifierToPixelFormat:PXTextureDataPixelFormat_RGBA5551]];
// This texture data will be stored as a 5551 texture; as in, 5 bytes for
// red, green, and blue and only 1 byte for alpha.
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];

Declared In

PXTextureLoader.m

Instance Methods

initWithContentsOfFile:

Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file could not be found, or the image format isn’t supported.

- (id)initWithContentsOfFile:(NSString *)path

Parameters

path

The path of the image file to load. The file path may be absolute or relative to the application bundle. The path may also omit the file extension, and Pixelwave will try to find a valid image with that name.

Example:

PXTextureLoader *textureLoader = [[PXTextureLoader alloc] initWithContentsOfFile:@"image.png"];
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];
[textureLoader release];

Declared In

PXTextureLoader.m

initWithContentsOfFile:modifier:

Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file could not be found, or the image format isn’t supported.

- (id)initWithContentsOfFile:(NSString *)path modifier:(id<PXTextureModifier>)_modifier

Parameters

path

The path of the image file to load. The file path may be absolute or relative to the application bundle. The path may also omit the file extension, and Pixelwave will try to find a valid image with that name.

modifier

A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

Example:

PXTextureLoader *textureLoader = [[PXTextureLoader alloc] initWithContentsOfFile:@"image.png"
                                                                        modifier:[PXTextureModifiers textureModifierToPixelFormat:PXTextureDataPixelFormat_RGBA5551]];
// This texture data will be stored as a 5551 texture; as in, 5 bytes for
// red, green, and blue and only 1 byte for alpha.
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];
[textureLoader release];

Declared In

PXTextureLoader.m

initWithContentsOfURL:

Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

- (id)initWithContentsOfURL:(NSURL *)url

Parameters

url

The url of the image to load.

Example:

PXTextureLoader *textureLoader = [[PXTextureLoader alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.myWebsite.com/image.png"]];
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];
[textureLoader release];

Declared In

PXTextureLoader.m

initWithContentsOfURL:modifier:

Creates a new PXTextureLoader instance containing the loaded image data. Returns nil if the file at the url could not be found, or the image format isn’t supported.

- (id)initWithContentsOfURL:(NSURL *)url modifier:(id<PXTextureModifier>)_modifier

Parameters

url

The url of the image to load.

modifier

A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

Example:

PXTextureLoader *textureLoader = [[PXTextureLoader alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.myWebsite.com/image.png"]
                                                                       modifier:[PXTextureModifiers textureModifierToPixelFormat:PXTextureDataPixelFormat_RGBA5551]];
// This texture data will be stored as a 5551 texture; as in, 5 bytes for
// red, green, and blue and only 1 byte for alpha.
PXTextureData *textureData = [textureLoader newTextureData];

// Add a copy of the texture to the display hierarchy.
PXTexture *texture = [[PXTexture alloc] initWithTextureData:textureData];
[self addChild:texture];
[texture release];

[textureData release];
[textureLoader release];

Declared In

PXTextureLoader.m

newTextureData

Creates a new PXTextureData object containing a copy of the loaded image data. Note that all returned copies must be released by the caller.

- (PXTextureData *)newTextureData

Return Value

The new texture data.

Declared In

PXTextureLoader.m

setContentScaleFactor:

Use this method to change the automatic contentScaleFactor adjustment that happens when an image is loaded in. It is not advised to use this method unless you know what you’re doing.

- (void)setContentScaleFactor:(float)val

Declared In

PXTextureLoader.m