Classes | Public Types | Public Member Functions

Tiny2D::Sprite Class Reference

Animated sprite instance. More...

#include <Tiny2D.h>

List of all members.

Classes

struct  DrawParams
 Sprite draw parameters. More...

Public Types

enum  AnimationMode {
  AnimationMode_Loop = 0, AnimationMode_Once, AnimationMode_OnceAndFreeze, AnimationMode_LoopWhenDone,
  AnimationMode_OnceWhenDone, AnimationMode_COUNT
}
 

Sprite animation mode.

More...
typedef void(* EventCallback )(const std::string &eventName, const std::string &eventValue, void *userData)
 Sprite event callback.

Public Member Functions

 Sprite ()
 Constructs an empty sprite.
 Sprite (const Sprite &other)
 Copy constructor; internally creates new sprite instance object (with its own state) and increases reference count of the sprite resource.
 ~Sprite ()
 Destructs sprite.
ResourceState GetState () const
 Gets resource state.
void operator= (const Sprite &other)
 Copy operator; internally creates new sprite instance object (with its own state) and increases reference count of the sprite resource.
bool Create (const std::string &name, bool immediate=true)
 Creates sprite from a file; name can either be the name of the .sprite.xml file or full path to the image file (including image file extension); 'immediate' set to true indicates to load it synchronously.
void Destroy ()
 Destroys the sprite.
void SetEventCallback (EventCallback callback, void *userData)
 Sets event callback (events are defined in .sprite.xml file)
void Update (float deltaTime)
 Updates sprite state by given delta time.
void PlayAnimation (const std::string &name=std::string(), AnimationMode mode=AnimationMode_Loop, float transitionTime=0.0f)
 Plays an animation of given name.
void Draw (const DrawParams *params)
 Draws the sprite.
void Draw (const Vec2 &position=Vec2(0.0f, 0.0f), float rotation=0)
 Draws the sprite.
void DrawCentered (const Vec2 &center=Vec2(0.0f, 0.0f), float rotation=0)
 Draws the sprite centered at given coordinates.
int GetWidth ()
 Gets sprite width.
int GetHeight ()
 Gets sprite height.

Detailed Description

Animated sprite instance.


Member Typedef Documentation

typedef void(* Tiny2D::Sprite::EventCallback)(const std::string &eventName, const std::string &eventValue, void *userData)

Sprite event callback.


Member Enumeration Documentation

Sprite animation mode.

Enumerator:
AnimationMode_Loop 

Infinite looping.

AnimationMode_Once 

Played once; then transitions back to default animation.

AnimationMode_OnceAndFreeze 

Play once and then freeze (no animation)

AnimationMode_LoopWhenDone 

Start infinite looping after current animation is done.

AnimationMode_OnceWhenDone 

Play once after current animation is done.

AnimationMode_COUNT 

Constructor & Destructor Documentation

Tiny2D::Sprite::Sprite (  )

Constructs an empty sprite.

Tiny2D::Sprite::Sprite ( const Sprite other )

Copy constructor; internally creates new sprite instance object (with its own state) and increases reference count of the sprite resource.

Tiny2D::Sprite::~Sprite (  )

Destructs sprite.


Member Function Documentation

bool Tiny2D::Sprite::Create ( const std::string &  name,
bool  immediate = true 
)

Creates sprite from a file; name can either be the name of the .sprite.xml file or full path to the image file (including image file extension); 'immediate' set to true indicates to load it synchronously.

void Tiny2D::Sprite::Destroy (  )

Destroys the sprite.

void Tiny2D::Sprite::Draw ( const DrawParams params )

Draws the sprite.

void Tiny2D::Sprite::Draw ( const Vec2 position = Vec2(0.0f, 0.0f),
float  rotation = 0 
)

Draws the sprite.

void Tiny2D::Sprite::DrawCentered ( const Vec2 center = Vec2(0.0f, 0.0f),
float  rotation = 0 
)

Draws the sprite centered at given coordinates.

int Tiny2D::Sprite::GetHeight (  )

Gets sprite height.

ResourceState Tiny2D::Sprite::GetState (  ) const

Gets resource state.

int Tiny2D::Sprite::GetWidth (  )

Gets sprite width.

void Tiny2D::Sprite::operator= ( const Sprite other )

Copy operator; internally creates new sprite instance object (with its own state) and increases reference count of the sprite resource.

void Tiny2D::Sprite::PlayAnimation ( const std::string &  name = std::string(),
AnimationMode  mode = AnimationMode_Loop,
float  transitionTime = 0.0f 
)

Plays an animation of given name.

void Tiny2D::Sprite::SetEventCallback ( EventCallback  callback,
void *  userData 
)

Sets event callback (events are defined in .sprite.xml file)

void Tiny2D::Sprite::Update ( float  deltaTime )

Updates sprite state by given delta time.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines