Inherits from PXDisplayObject : PXEventDispatcher : NSObject
Declared in PXTexture.h
PXTexture.m

Overview

Used for drawing PXTextureData objects to the screen. A PXTexture is a subclass of the PXDisplayObject which can be specified to render an entire texture or just a specific area.

Tasks

Properties

anchorX

The horizontal anchor position in percent. If the texture was 32x64 and you set the anchor to 0.5f, the horizontal position in point coordinates would be 16. The anchor position is what the texture will rotate, scale, and position around.

@property (nonatomic, assign) float anchorX

Declared In

PXTexture.h

anchorY

The vertical anchor position in percent. If the texture was 32x64 and you set the anchor to 0.5f, the vertical position in point coordinates would be 32. The anchor position is what the texture will rotate, scale, and position around.

@property (nonatomic, assign) float anchorY

Declared In

PXTexture.h

clipRect

The clip area of the texture data that this texture is representing. To show the entire image, set this property to nil.

@property (nonatomic, copy) PXClipRect *clipRect

Discussion

Since the clip rectangle is closely tied to the textureData, if the textureData property is nil, this property will remain nil. Also, setting the textureData property wipes out the current clipRect, so make sure to set the clipRect AFTER setting the textureData property.

Thus if the texture is 256x256 pixels, and you only want a 32x64 segment, the clip rect is what would be set to achieve this.

Declared In

PXTexture.h

contentHeight

The height of the clipping area, or of the textureData property if no clipping area is set.

@property (nonatomic, readonly) float contentHeight

Declared In

PXTexture.h

contentRotation

The rotation offset of the content, as defined by the texture’s clip rectangle.

@property (nonatomic, readonly) float contentRotation

Discussion

default 0

Declared In

PXTexture.h

contentWidth

The width of the clipping area, or of the textureData property if no clipping area is set.

@property (nonatomic, readonly) float contentWidth

Declared In

PXTexture.h

repeat

Determines how pixels outside of the texture’s boundaries should be handled. If the clipRect of the texture is outside of the bounds of the texture, setting repeat to YES will simply repeat the texture’s pixels to fill the gap. If set to NO, the 1-pixel boundary around the edge of will be stretched to fill the gap.

@property (nonatomic, assign) BOOL repeat

Declared In

PXTexture.h

smoothing

Determines whether pixel smoothing will be turned on when the texture is scaled or rotated. Note that while smoothing looks better it is also more taxing on the gpu.

@property (nonatomic, assign) BOOL smoothing

Declared In

PXTexture.h

textureData

The texture data that this texture represents.

@property (nonatomic, assign) PXTextureData *textureData

Declared In

PXTexture.h

Class Methods

texture

/

+ (PXTexture *)texture

Declared In

PXTexture.h

textureWithContentsOfFile:

+ (PXTexture *)textureWithContentsOfFile:(NSString *)path

Declared In

PXTexture.m

textureWithContentsOfFile:modifier:

+ (PXTexture *)textureWithContentsOfFile:(NSString *)path modifier:(id<PXTextureModifier>)modifier

Declared In

PXTexture.m

textureWithContentsOfURL:

+ (PXTexture *)textureWithContentsOfURL:(NSURL *)url

Declared In

PXTexture.m

textureWithContentsOfURL:modifier:

+ (PXTexture *)textureWithContentsOfURL:(NSURL *)url modifier:(id<PXTextureModifier>)modifier

Declared In

PXTexture.m

textureWithData:

+ (PXTexture *)textureWithData:(NSData *)data

Declared In

PXTexture.m

textureWithData:modifier:

+ (PXTexture *)textureWithData:(NSData *)data modifier:(id<PXTextureModifier>)modifier

Declared In

PXTexture.m

textureWithTextureData:

Creates an autoreleased PXTexture object with the given PXTextureData object

+ (PXTexture *)textureWithTextureData:(PXTextureData *)textureData

See Also

Declared In

PXTexture.m

Instance Methods

initWithTextureData:

Creates a texture that represents the specified texture data.

- (id)initWithTextureData:(PXTextureData *)_textureData

Parameters

texture

The texture data that this texture represents.

Example:

PXTextureLoader *loader = [[PXTextureLoader alloc] initWithContentsOfFile:@"happy.png"];
PXTextureData *data = [loader newTextureData]; 
PXTexture *tex = [[PXTexture alloc] initWithTextureData:data];

Declared In

PXTexture.m

setAnchorWithPointX:pointY:

Sets anchor position in points, relative to the current textureData. If textureData is nil, this method call is ignored.

- (void)setAnchorWithPointX:(float)x pointY:(float)y

Parameters

x

The horizontal anchor position in points, within the textureData.

y

The vertical anchor position in points, within the textureData.

Example:

PXTextureLoader *loader = [[PXTextureLoader alloc] initWithContentsOfFile:@"happy.png"];
PXTextureData *data = [loader newTextureData]; 
PXTexture *tex = [[PXTexture alloc] initWithTextureData:data];

[tex setAnchorWithPointX:16 pointY:32];
// tex would represent the happy image.  Assuming happy is a 32x64 image,
// then its anchor will be at (16, 32) in local point coordinates.

Declared In

PXTexture.m

setClipRectWithX:y:width:height:

Sets the clip area and anchor point in one call.

- (void)setClipRectWithX:(float)x y:(float)y width:(float)width height:(float)height

Parameters

x

The left position of the clip rectangle in points.

y

The top position of the clip rectangle in points.

width

The width of the clip rectangle in points.

height

The height of the clip rectangle in points.

anchorX

The horizontal anchor position, in percent.

anchorY

The vertical anchor position, in percent.

Example:

PXTextureLoader *loader = [[PXTextureLoader alloc] initWithContentsOfFile:@"happy.png"];
PXTextureData *data = [loader newTextureData]; 
PXTexture *tex = [[PXTexture alloc] initWithTextureData:data];

[tex setClipRectWithX:16 y:16 width:32 height:64 usingAnchorX:0.5f anchorY:0.5f];
// tex would represent a 32x64 image that is part of the whole image of
// happy, starting at (16, 16).  Its anchor will be at (16, 32) in local
// point coordinates.

Declared In

PXTexture.m