Inherits from SPDisplayObjectContainer : SPDisplayObject : SPEventDispatcher : NSObject
Declared in SPSprite.h

Overview

An SPSprite is the most lightweight, non-abstract container class.

Use it as a simple means of grouping objects together in one coordinate system.

SPSprite *sprite = [SPSprite sprite];

// create children
SPImage *venus = [SPImage imageWithContentsOfFile:@"venus.png"];
SPImage *mars = [SPImage imageWithContentsOfFile:@"mars.png"];

// move children to some relative positions
venus.x = 50;
mars.x = -20;

// add children to the sprite
[sprite addChild:venus];
[sprite addChild:mars];

// calculate total width of all children
float totalWidth = sprite.width;

// rotate the whole group
sprite.rotation = PI;

Flattened Sprites

The flatten-method allows you to optimize the rendering of static parts of your display list.

It analyzes the tree of children attached to the sprite and optimizes the rendering calls in a way that makes rendering extremely fast. The speed-up comes at a price, though: you will no longer see any changes in the properties of the children (position, rotation, alpha, etc). To update the object after changes have happened, simply call flatten again, or unflatten the object.

Tasks

Initialization

Methods

  • – flatten

    Optimizes the sprite for optimal rendering performance. Changes in the children of a flattened sprite will not be displayed any longer. For this to happen, either call flatten again, or unflatten the sprite. Beware that the actual flattening will not happen right away, but right before the next rendering.

  • – unflatten

    Removes the rendering optimizations that were created when flattening the sprite. Changes to the sprite’s children will immediately become visible again.

  • – clipRectInSpace:

    Returns the bounds of the container’s clipRect in the given coordinate space, or null if the sprite doens’t have a clipRect.

Properties

  •   isFlattened

    Returns YES if this sprite has been flattened.

    property
  •   clipRect

    The sprite’s clipping rectangle in its local coordinate system. Only pixels within this rectangle will be drawn. The clipping rectangle is axis aligned with the screen, so it will not be rotated or skewed if the sprite is.

    property

Properties

clipRect

The sprite’s clipping rectangle in its local coordinate system. Only pixels within this rectangle will be drawn. The clipping rectangle is axis aligned with the screen, so it will not be rotated or skewed if the sprite is.

@property (nonatomic, copy) SPRectangle *clipRect

Discussion

The sprite’s clipping rectangle in its local coordinate system. Only pixels within this rectangle will be drawn. The clipping rectangle is axis aligned with the screen, so it will not be rotated or skewed if the sprite is.

Declared In

SPSprite.h

isFlattened

Returns YES if this sprite has been flattened.

@property (nonatomic, readonly) BOOL isFlattened

Discussion

Returns YES if this sprite has been flattened.

Declared In

SPSprite.h

Class Methods

sprite

Create a new, empty sprite.

+ (instancetype)sprite

Discussion

Create a new, empty sprite.

Declared In

SPSprite.h

Instance Methods

clipRectInSpace:

Returns the bounds of the container’s clipRect in the given coordinate space, or null if the sprite doens’t have a clipRect.

- (SPRectangle *)clipRectInSpace:(SPDisplayObject *)targetSpace

Discussion

Returns the bounds of the container’s clipRect in the given coordinate space, or null if the sprite doens’t have a clipRect.

Declared In

SPSprite.h

flatten

Optimizes the sprite for optimal rendering performance. Changes in the children of a flattened sprite will not be displayed any longer. For this to happen, either call flatten again, or unflatten the sprite. Beware that the actual flattening will not happen right away, but right before the next rendering.

- (void)flatten

Discussion

Optimizes the sprite for optimal rendering performance. Changes in the children of a flattened sprite will not be displayed any longer. For this to happen, either call flatten again, or unflatten the sprite. Beware that the actual flattening will not happen right away, but right before the next rendering.

Declared In

SPSprite.h

unflatten

Removes the rendering optimizations that were created when flattening the sprite. Changes to the sprite’s children will immediately become visible again.

- (void)unflatten

Discussion

Removes the rendering optimizations that were created when flattening the sprite. Changes to the sprite’s children will immediately become visible again.

Declared In

SPSprite.h