overview wiki api reference download
 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:
gameplay::Ref gameplay::Drawable gameplay::AnimationTarget

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 Vector2getAnchor () const
void setFlip (int flipFlags)
int getFlip () const
void setFrameSource (unsigned int frameIndex, const Rectangle &source)
const RectanglegetFrameSource (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 Vector4getColor () const
void setBlendMode (BlendMode mode)
BlendMode getBlendMode () const
Texture::SamplergetSampler () const
RenderState::StateBlockgetStateBlock () const
MaterialgetMaterial () const
unsigned int draw (bool wireframe=false)

Static Public Member Functions

static Spritecreate (const char *imagePath, float width=-1, float height=-1, Effect *effect=NULL)
static Spritecreate (const char *imagePath, float width, float height, const Rectangle &source, unsigned int frameCount=1, Effect *effect=NULL)
static Spritecreate (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 ()
Spriteoperator= (const Sprite &sprite)
Drawableclone (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

Defines the blend modes.

Defines the flip flags used for rendering the sprite.

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:
frameStrideThe number of frames to move across before moving down or wrapping to the top.
framePaddingThe 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:
imagePathThe path to the image to create the sprite from.
widthThe width of a frame.
heightThe width of a frame.
effectThe 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:
imagePathThe path to the image to create the sprite from.
widthThe width of a frame.
heightThe width of a frame.
sourceThe starting frame source region used from the image.
frameCountThe number from frames to source clips from.
effectThe custom effect to render with.
Returns:
The new sprite.
static Sprite* gameplay::Sprite::create ( Properties properties) [static]

Creates a sprite from properties.

Parameters:
propertiesThe 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.

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]
void gameplay::Sprite::getAnimationPropertyValue ( int  propertyId,
AnimationValue value 
) [protected, virtual]
See also:
AnimationTarget::getAnimationProperty

Implements gameplay::AnimationTarget.

Gets the blend mode for the sprite.

Returns:
The blend mode for the sprite.
See also:
Sprite::BlendMode

Gets the color (RGBA) for the sprite.

Returns:
The color(RGBA) for the sprite.

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:
frameIndexThe 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.

Gets the material used by sprite batch.

Returns:
The material used by the sprite batch.

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.

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]

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.

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:
anchorThe 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.

Sets the blend mode for the sprite.

Parameters:
modeThe blend mode for the sprite.
See also:
Sprite::BlendMode
void gameplay::Sprite::setColor ( const Vector4 color)

Sets the color (RGBA) for the sprite.

Parameters:
colorThe color(RGBA) for the sprite.
void gameplay::Sprite::setFlip ( int  flipFlags)

Sets the flip flags used for rendering the sprite.

Parameters:
flipFlagsThe 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:
indexThe 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:
frameIndexThe frame index to specify the source region for.
sourceThe source clip region from the source image.

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:
offsetThe 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:
opacityThe 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