e2d::graphics::Sprite Class Reference

Inheritance diagram for e2d::graphics::Sprite:

e2d::graphics::Animation e2d::core::Rect

List of all members.


Detailed Description

In Easy2D, a Sprite is, basically, an animated figure with a position relative to the surface where it will be blitted. This class is a child of Animation, so you may want to assign an AnimationMap to it so it shall behave as a real animated sprite.

Sprites can be loaded from xml files the same way TileMap s are. The format for the xml file is as follows:

  <?xml version="1.0"?>
  <sprite name="mysprite">
     <tileset ...>
        ...
     </tileset>
     <animations>
        ...
     </animations>
  </sprite>

The <tileset> tag must follow the format described in the Tileset class. For the optional <animations> tag, see the documentation of AnimationMap. Easy2D will just consider the first ocurrence of each of these two tags in the file, the order does not matter. Loading a sprite this way will cause the AnimationMap to be automatically created and assigned to the Sprite.

When loading a sprite from a xml file, the tileset and the animation map will automatically be stored in (or recovered from) the ResourceMap. The name of the tileset will be the string in the attribute "name" of the <tileset> tag, and the name of the animation map will be the string in the "name" attribute of the <sprite> tag.

Public Member Functions

 Sprite (const Sprite &original)
 Copy Constructor.
void Blit (SDL_Surface *destination)
 Blits the sprite on the surface.
TilesetGetTileset ()
 Gets the tileset assigned for this sprite.
void Load (char *filename)
 Loads a sprite from a xml file.
void Optimize (void)
 Optimizes blitting.
void SetTileset (Tileset *tileset)
 Assigns a tileset for this sprite.


Constructor & Destructor Documentation

e2d::graphics::Sprite::Sprite ( const Sprite original  ) 

After loading a sprite from a xml file, you don't need to go through all the overhead of reading the xml again and recovering the resources from the resource map. If the new sprite uses the same image and animation sequence, just make a copy; it's way faster.

Parameters:
original The original sprite to copy assignements from.


Member Function Documentation

void e2d::graphics::Sprite::Blit ( SDL_Surface *  destination  ) 

Blits the image in the tileset pointed by the "current frame" attribute of Animation into the selected surface. If an animation is running, method Blit will always blit the current frame of the animation.

Parameters:
destination Surface where the sprite shall be blitted.
Exceptions:
Exception if there's no tileset assigned to this sprite.

Tileset * e2d::graphics::Sprite::GetTileset (  ) 

Returns:
a pointer to the tileset assigned to this sprite, or NULL if no tileset was assigned.

void e2d::graphics::Sprite::Load ( char *  filename  ) 

Loads a sprite from a xml file, in the format described above.

Parameters:
filename Path to the xml sprite file.
Exceptions:
Exception if any parsing error occurs.

void e2d::graphics::Sprite::Optimize ( void   ) 

Calls Tileset::Optimize on this sprite's tileset.

void e2d::graphics::Sprite::SetTileset ( Tileset tileset  ) 

Assigns a tileset for this sprite, changing the sprite's width and height (members of Rect). Note that if you don't change the animation map accordingly, unexpected results may occurr when trying to animate this sprite.

Parameters:
tileset The new tileset for this sprite.


Generated on Tue Dec 8 10:32:45 2009 for Easy2D by  doxygen 1.5.6