Dragonfly 4.19
A text-based game engine
Public Member Functions | Private Attributes | List of all members
df::Animation Class Reference

Public Member Functions

 Animation ()
 
void setSprite (Sprite *p_new_sprite)
 
const SpritegetSprite () const
 
void setName (std::string new_name)
 
std::string getName () const
 
void setIndex (int new_index)
 
int getIndex () const
 
void setSlowdownCount (int new_slowdown_count)
 
int getSlowdownCount () const
 
Box getBox () const
 
virtual std::string serialize (std::string attr="")
 
virtual int deserialize (std::string s)
 
bool isModified () const
 
int draw (Vector position)
 

Private Attributes

Spritem_p_sprite
 
int m_index
 
int m_slowdown_count
 
std::string m_name
 
bool m_modified
 

Constructor & Destructor Documentation

◆ Animation()

df::Animation::Animation ( )

Animation constructor.

Member Function Documentation

◆ deserialize()

virtual int df::Animation::deserialize ( std::string  s)
virtual

Deserialize string to become attributes and apply.

Return 0 if no errors, else -1.

◆ draw()

int df::Animation::draw ( Vector  position)

Draw single frame centered at position (x,y).

Drawing accounts for slowdown, and advances Sprite frame. Return 0 if ok, else -1.

◆ getBox()

Box df::Animation::getBox ( ) const

Get bounding box of associated Sprite.

◆ getIndex()

int df::Animation::getIndex ( ) const

Get index of current Sprite frame to be displayed.

◆ getName()

std::string df::Animation::getName ( ) const

Get Sprite name (in ResourceManager).

◆ getSlowdownCount()

int df::Animation::getSlowdownCount ( ) const

Set animation slowdown count (-1 means stop animation).

◆ getSprite()

const Sprite * df::Animation::getSprite ( ) const

Return pointer to associated Sprite.

◆ isModified()

bool df::Animation::isModified ( ) const

Return true if any attributes modified since last serialize.

◆ serialize()

virtual std::string df::Animation::serialize ( std::string  attr = "")
virtual

Serialize attributes to string.

e.g., sprite_name:saucer,sprite_transparency:0,sprite_index:2,... Default ("") is only attributes modified since last serialize(). If attr is "ALL" then serialize (modified or not). Clear modified attribute. Returns "" if nothing modified.

◆ setIndex()

void df::Animation::setIndex ( int  new_index)

Set index of current Sprite frame to be displayed.

◆ setName()

void df::Animation::setName ( std::string  new_name)

Set Sprite name (in ResourceManager).

◆ setSlowdownCount()

void df::Animation::setSlowdownCount ( int  new_slowdown_count)

Set animation slowdown count (-1 means stop animation).

◆ setSprite()

void df::Animation::setSprite ( Sprite p_new_sprite)

Set associated Sprite to new one.

Note, Sprite is managed by ResourceManager. Set Sprite index to 0 (first frame).

Member Data Documentation

◆ m_index

int df::Animation::m_index
private

Current index frame for Sprite.

◆ m_modified

bool df::Animation::m_modified
private

True if modified since serialize().

◆ m_name

std::string df::Animation::m_name
private

◆ m_p_sprite

Sprite* df::Animation::m_p_sprite
private

Sprite associated with Animation.

◆ m_slowdown_count

int df::Animation::m_slowdown_count
private

Slowdown counter (-1 means stop).