|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Functions Variables Typedefs Enumerations Enumerator
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
gameplay::Sprite Class Reference

`#include <Sprite.h>`

Inheritance diagram for gameplay::Sprite:

List of all members.

## Public Types

enum

Offset {
OFFSET_LEFT = 0x01, OFFSET_HCENTER = 0x02, OFFSET_RIGHT = 0x04, OFFSET_TOP = 0x10,
OFFSET_VCENTER = 0x20, OFFSET_BOTTOM = 0x40, OFFSET_ANCHOR = 0x80, OFFSET_TOP_LEFT = OFFSET_TOP | OFFSET_LEFT,
OFFSET_VCENTER_LEFT = OFFSET_VCENTER | OFFSET_LEFT, OFFSET_BOTTOM_LEFT = OFFSET_BOTTOM | OFFSET_LEFT, OFFSET_TOP_HCENTER = OFFSET_TOP | OFFSET_HCENTER, OFFSET_VCENTER_HCENTER = OFFSET_VCENTER | OFFSET_HCENTER,
OFFSET_BOTTOM_HCENTER = OFFSET_BOTTOM | OFFSET_HCENTER, OFFSET_TOP_RIGHT = OFFSET_TOP | OFFSET_RIGHT, OFFSET_VCENTER_RIGHT = OFFSET_VCENTER | OFFSET_RIGHT, OFFSET_BOTTOM_RIGHT = OFFSET_BOTTOM | OFFSET_RIGHT
}

enum | FlipFlags { FLIP_NONE, FLIP_VERTICAL, FLIP_HORIZONTAL }
enum | BlendMode { BLEND_NONE, BLEND_ALPHA, BLEND_ADDITIVE, BLEND_MULTIPLIED }

## Public Member Functions

float | getWidth () const
float | getHeight () const
void | setOffset (Offset offset)
Offset | getOffset () const
void | setAnchor (const Vector2 &anchor)
const Vector2 & | getAnchor () const
void | setFlip (int flipFlags)
int | getFlip () const
void | setFrameSource (unsigned int frameIndex, const Rectangle &source)
const Rectangle & | getFrameSource (unsigned int frameIndex) const
void | computeFrames (unsigned int frameStride=0, unsigned int framePadding=1)
unsigned int | getFrameCount () const
unsigned int | getFrameStride () const
unsigned int | getFramePadding () const
void | setFrameIndex (unsigned int index)
unsigned int | getFrameIndex () const
void | setOpacity (float opacity)
float | getOpacity () const
void | setColor (const Vector4 &color)
const Vector4 & | getColor () const
void | setBlendMode (BlendMode mode)
BlendMode | getBlendMode () const
Texture::Sampler * | getSampler () const
RenderState::StateBlock * | getStateBlock () const
Material * | getMaterial () const
unsigned int | draw (bool wireframe=false)

## Static Public Member Functions

static Sprite * | create (const char *imagePath, float width=-1, float height=-1, Effect *effect=NULL)
static Sprite * | create (const char *imagePath, float width, float height, const Rectangle &source, unsigned int frameCount=1, Effect *effect=NULL)
static Sprite * | create (Properties *properties)

## Static Public Attributes

static const int | ANIMATE_OPACITY = 1
static const int | ANIMATE_COLOR = 2
static const int | ANIMATE_KEYFRAME = 3

## Protected Member Functions

| Sprite ()
| ~Sprite ()
Sprite & | operator= (const Sprite &sprite)
Drawable * | clone (NodeCloneContext &context)
int | getPropertyId (TargetType type, const char *propertyIdStr)
unsigned int | getAnimationPropertyComponentCount (int propertyId) const
void | getAnimationPropertyValue (int propertyId, AnimationValue *value)
void | setAnimationPropertyValue (int propertyId, AnimationValue *value, float blendWeight=1.0f)

## Detailed Description

Defines a sprite for rendering a 2D region.

A sprite has alignment for controlling the local offset bounds. A sprite has an anchor for controlling the origin for rotation and physics.

You can add transformation and hierarchial by attaching sprites to Nodes within a Scene.

The active camera in a scene effects the rendering location in the viewport for each sprite.

Sprites can be animated using the animation system. Sprites can have physics applied to them via their node binding.

## Member Enumeration Documentation

enum gameplay::Sprite::BlendMode

Defines the blend modes.

enum gameplay::Sprite::FlipFlags

Defines the flip flags used for rendering the sprite.

enum gameplay::Sprite::Offset

Defines the offset for position.

## Constructor & Destructor Documentation

gameplay::Sprite::Sprite | ( |  | ) | `[protected]`

Constructor.

gameplay::Sprite::~Sprite | ( |  | ) | `[protected]`

Destructor.

## Member Function Documentation

Drawable* gameplay::Sprite::clone | ( | NodeCloneContext & | context | ) | `[protected, virtual]`

See also:
  Drawable::clone

Implements gameplay::Drawable.

void gameplay::Sprite::computeFrames | ( | unsigned int | frameStride = `0`,
|  | unsigned int | framePadding = `1`
| ) |  |

Computes the source frames for sprites with frameCount > 1.

This walks the image starting from the first source region and traverses the image moving across the image by the frame stride and then wrapping at the edges of the image.

Parameters:

  frameStride | The number of frames to move across before moving down or wrapping to the top.
  framePadding | The number of pixels used as padding between frame.

static Sprite* gameplay::Sprite::create | ( | const char * | imagePath,
|  | float | width = `-1`,
|  | float | height = `-1`,
|  | Effect * | effect = `NULL`
| ) |  | `[static]`

Create a sprite image using

Parameters:

  imagePath | The path to the image to create the sprite from.
  width | The width of a frame.
  height | The width of a frame.
  effect | The custom effect to render with.

Returns:
  The new sprite.

static Sprite* gameplay::Sprite::create | ( | const char * | imagePath,
|  | float | width,
|  | float | height,
|  | const Rectangle & | source,
|  | unsigned int | frameCount = `1`,
|  | Effect * | effect = `NULL`
| ) |  | `[static]`

Creates a sprite from a user specified source region within the image.

Passing -1 for width/height or source.width/.height, will default to using the images width/height.

Parameters:

  imagePath | The path to the image to create the sprite from.
  width | The width of a frame.
  height | The width of a frame.
  source | The starting frame source region used from the image.
  frameCount | The number from frames to source clips from.
  effect | The custom effect to render with.

Returns:
  The new sprite.

static Sprite* gameplay::Sprite::create | ( | Properties * | properties | ) | `[static]`

Creates a sprite from properties.

Parameters:

  properties | The properties object to create from.

Returns:
  The new Sprite.

unsigned int gameplay::Sprite::draw | ( | bool | wireframe = `false` | ) | `[virtual]`

See also:
  Drawable::draw

Implements gameplay::Drawable.

const Vector2& gameplay::Sprite::getAnchor | ( |  | ) | const

Gets the anchor which is a origin ratio of the sprite width and height from [0.0,1.0].

Returns:
  The anchor which is a origin ratio of the sprite width and height from [0.0,1.0].

unsigned int gameplay::Sprite::getAnimationPropertyComponentCount | ( | int | propertyId | ) | const`[protected, virtual]`

See also:
  AnimationTarget::getAnimationPropertyComponentCount

Implements gameplay::AnimationTarget.

void gameplay::Sprite::getAnimationPropertyValue | ( | int | propertyId,
|  | AnimationValue * | value
| ) |  | `[protected, virtual]`

See also:
  AnimationTarget::getAnimationProperty

Implements gameplay::AnimationTarget.

BlendMode gameplay::Sprite::getBlendMode | ( |  | ) | const

Gets the blend mode for the sprite.

Returns:
  The blend mode for the sprite.

See also:
  Sprite::BlendMode

const Vector4& gameplay::Sprite::getColor | ( |  | ) | const

Gets the color (RGBA) for the sprite.

Returns:
  The color(RGBA) for the sprite.

int gameplay::Sprite::getFlip | ( |  | ) | const

Gets the flip flags used for rendering the sprite.

Returns:
  The flip flags used for rendering the sprite.

See also:
  Sprite::FlipFlags

unsigned int gameplay::Sprite::getFrameCount | ( |  | ) | const

Gets the number of frames this sprite can render.

Returns:
  The total number of frames this sprite can render.

unsigned int gameplay::Sprite::getFrameIndex | ( |  | ) | const

Gets the current frame index to be rendered.

Returns:
  The current frame index to be rendered.

unsigned int gameplay::Sprite::getFramePadding | ( |  | ) | const

Gets the source padding in pixels around the source region.

Returns:
  The source flip flags from the source image.

See also:
  Sprite::FlipFlags

const Rectangle& gameplay::Sprite::getFrameSource | ( | unsigned int | frameIndex | ) | const

Gets the source region from the source image.

Parameters:

  frameIndex | The frame index to get the source region from.

Returns:
  The source clip region from the source image.

unsigned int gameplay::Sprite::getFrameStride | ( |  | ) | const

Gets the number of frames to travel across before wrapping to the next row or column.

Returns:
  The total number of frames this sprite can render.

float gameplay::Sprite::getHeight | ( |  | ) | const

Gets the height of the sprite.

Returns:
  The height of the sprite.

Material* gameplay::Sprite::getMaterial | ( |  | ) | const

Gets the material used by sprite batch.

Returns:
  The material used by the sprite batch.

Offset gameplay::Sprite::getOffset | ( |  | ) | const

Gets the offset used for how much to locally adjust the bounds of the sprite.

Note: The default offset is Offset::OFFSET_BOTTOM_LEFT

Returns:
  The offset used for how much to locally adjust the bounds of the sprite.

float gameplay::Sprite::getOpacity | ( |  | ) | const

Gets the opacity for the sprite.

The range is from full transparent to opaque [0.0,1.0].

Returns:
  The opacity for the sprite.

int gameplay::Sprite::getPropertyId | ( | TargetType | type,
|  | const char * | propertyIdStr
| ) |  | `[protected, virtual]`

See also:
  AnimationTarget::getPropertyId

Reimplemented from gameplay::AnimationTarget.

Texture::Sampler* gameplay::Sprite::getSampler | ( |  | ) | const

Gets the texture sampler used when sampling the texture. This can be modified for controlling sampler setting such as filtering modes.

Returns:
  The texture sampler used when sampling the texture.

RenderState::StateBlock* gameplay::Sprite::getStateBlock | ( |  | ) | const

Gets the StateBlock for the SpriteBatch.

The returned state block controls the renderer state used when drawing items with this sprite batch. Modification can be made to the returned state block to change how primitives are rendered.

Returns:
  The StateBlock for this SpriteBatch.

float gameplay::Sprite::getWidth | ( |  | ) | const

Gets the width of the sprite.

Returns:
  The width of the sprite.

Sprite& gameplay::Sprite::operator= | ( | const Sprite & | sprite | ) | `[protected]`

operator=

void gameplay::Sprite::setAnchor | ( | const Vector2 & | anchor | ) |

Sets the anchor which is a origin ratio of the sprite width and height from [0.0,1.0].

Parameters:

  anchor | The anchor which is a origin ratio of the sprite width and height from [0.0,1.0].

void gameplay::Sprite::setAnimationPropertyValue | ( | int | propertyId,
|  | AnimationValue * | value,
|  | float | blendWeight = `1.0f`
| ) |  | `[protected, virtual]`

See also:
  AnimationTarget::setAnimationProperty

Implements gameplay::AnimationTarget.

void gameplay::Sprite::setBlendMode | ( | BlendMode | mode | ) |

Sets the blend mode for the sprite.

Parameters:

  mode | The blend mode for the sprite.

See also:
  Sprite::BlendMode

void gameplay::Sprite::setColor | ( | const Vector4 & | color | ) |

Sets the color (RGBA) for the sprite.

Parameters:

  color | The color(RGBA) for the sprite.

void gameplay::Sprite::setFlip | ( | int | flipFlags | ) |

Sets the flip flags used for rendering the sprite.

Parameters:

  flipFlags | The flip flags used for rendering the sprite.

See also:
  Sprite::FlipFlags

void gameplay::Sprite::setFrameIndex | ( | unsigned int | index | ) |

Sets the current frame index to be rendered.

Parameters:

  index | The current frame index to be rendered.

void gameplay::Sprite::setFrameSource | ( | unsigned int | frameIndex,
|  | const Rectangle & | source
| ) |  |

Sets the source region from the source image.

Parameters:

  frameIndex | The frame index to specify the source region for.
  source | The source clip region from the source image.

void gameplay::Sprite::setOffset | ( | Offset | offset | ) |

Sets the offset used for how much to locally adjust the bounds of the sprite.

Note: The default offset is Offset::OFFSET_BOTTOM_LEFT

Parameters:

  offset | The offset used for how much to locally adjust the bounds of the sprite.

void gameplay::Sprite::setOpacity | ( | float | opacity | ) |

Sets the opacity for the sprite.

The range is from full transparent to opaque [0.0,1.0].

Parameters:

  opacity | The opacity for the sprite.

## Member Data Documentation

const int gameplay::Sprite::ANIMATE_COLOR = 2`[static]`

Color property. Data = red, green, blue, alpha

const int gameplay::Sprite::ANIMATE_KEYFRAME = 3`[static]`

Image keyframe index property. Data=index

const int gameplay::Sprite::ANIMATE_OPACITY = 1`[static]`

Opacity property. Data=opacity

All Classes Functions Variables Typedefs Enumerations Enumerator