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. |
|Tileset *||GetTileset ()|
|Gets the tileset assigned for this sprite. |
|void||Load (char *filename)|
|Loads a sprite from a xml file. |
|Optimizes blitting. |
|void||SetTileset (Tileset *tileset)|
|Assigns a tileset for this sprite. |
|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.
|original||The original sprite to copy assignements from.|
|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.
|destination||Surface where the sprite shall be blitted.|
|Exception||if there's no tileset assigned to this sprite.|
|Tileset * e2d::graphics::Sprite::GetTileset||(||)|
|void e2d::graphics::Sprite::Load||(||char *||filename||)|
Loads a sprite from a xml file, in the format described above.
|filename||Path to the xml sprite file.|
|Exception||if any parsing error occurs.|
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.
|tileset||The new tileset for this sprite.|