#include <Sprite.h>
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) |
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.
Defines the blend modes.
Defines the flip flags used for rendering the sprite.
Defines the offset for position.
gameplay::Sprite::Sprite | ( | ) | [protected] |
Constructor.
gameplay::Sprite::~Sprite | ( | ) | [protected] |
Destructor.
Drawable* gameplay::Sprite::clone | ( | NodeCloneContext & | context | ) | [protected, virtual] |
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.
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
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. |
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.
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. |
static Sprite* gameplay::Sprite::create | ( | Properties * | properties | ) | [static] |
Creates a sprite from properties.
properties | The properties object to create from. |
unsigned int gameplay::Sprite::draw | ( | bool | wireframe = false | ) | [virtual] |
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].
unsigned int gameplay::Sprite::getAnimationPropertyComponentCount | ( | int | propertyId | ) | const [protected, virtual] |
Implements gameplay::AnimationTarget.
void gameplay::Sprite::getAnimationPropertyValue | ( | int | propertyId, |
AnimationValue * | value | ||
) | [protected, virtual] |
Implements gameplay::AnimationTarget.
BlendMode gameplay::Sprite::getBlendMode | ( | ) | const |
Gets the blend mode for the sprite.
const Vector4& gameplay::Sprite::getColor | ( | ) | const |
Gets the color (RGBA) for the sprite.
int gameplay::Sprite::getFlip | ( | ) | const |
Gets the flip flags used for rendering the sprite.
unsigned int gameplay::Sprite::getFrameCount | ( | ) | const |
Gets the number of frames this sprite can render.
unsigned int gameplay::Sprite::getFrameIndex | ( | ) | const |
Gets the current frame index to be rendered.
unsigned int gameplay::Sprite::getFramePadding | ( | ) | const |
Gets the source padding in pixels around the source region.
const Rectangle& gameplay::Sprite::getFrameSource | ( | unsigned int | frameIndex | ) | const |
Gets the source region from the source image.
frameIndex | The frame index to get the source region from. |
unsigned int gameplay::Sprite::getFrameStride | ( | ) | const |
Gets the number of frames to travel across before wrapping to the next row or column.
float gameplay::Sprite::getHeight | ( | ) | const |
Gets the height of the sprite.
Material* gameplay::Sprite::getMaterial | ( | ) | const |
Gets the material used by 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
float gameplay::Sprite::getOpacity | ( | ) | const |
Gets the opacity for the sprite.
The range is from full transparent to opaque [0.0,1.0].
int gameplay::Sprite::getPropertyId | ( | TargetType | type, |
const char * | propertyIdStr | ||
) | [protected, virtual] |
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.
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.
float gameplay::Sprite::getWidth | ( | ) | const |
Gets the width of the sprite.
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].
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] |
Implements gameplay::AnimationTarget.
void gameplay::Sprite::setBlendMode | ( | BlendMode | mode | ) |
Sets the blend mode for the sprite.
mode | The blend mode for the sprite. |
void gameplay::Sprite::setColor | ( | const Vector4 & | color | ) |
Sets the color (RGBA) for the sprite.
color | The color(RGBA) for the sprite. |
void gameplay::Sprite::setFlip | ( | int | flipFlags | ) |
Sets the flip flags used for rendering the sprite.
flipFlags | The flip flags used for rendering the sprite. |
void gameplay::Sprite::setFrameIndex | ( | unsigned int | index | ) |
Sets the current frame index to be rendered.
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.
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
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].
opacity | The opacity for the sprite. |
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