Animation class
class Animation
{
sf::Image img;
std::list<AnimationFrame> frames;
AnimationFrame currentFrame;
void CheckFrames();
public:
void LoadFromFile( std::string filename );
void SetPos( float x, float y );
sf::Sprite Output();
};
Function to load image
void Animation::LoadFromFile( std::string filename )
{
XMLDocument file;
file.LoadFile( filename.c_str() );
XMLElement* root = file.RootElement();
img.LoadFromFile( root->Attribute( "image" ) );
int w, h;
w = root->IntAttribute( "w" );
h = root->IntAttribute( "h" );
}
Function to store in list
void BuildMapFromFile( std::string filename )
{
XMLDocument file;
file.LoadFile( filename.c_str() );
XMLElement* root = file.RootElement();
//obj_animation
for( XMLElement* animation = root->FirstChildElement( "animation" ); animation; animation = animation->NextSiblingElement( "animation" ) )
{
//object
object new_object;
new_object.type = "animation";
int depth = animation->IntAttribute( "depth" );
new_object.depth = depth;
new_object._animation.LoadFromFile( animation->Attribute( "source" ) ); //loads image
new_object._animation.SetPos( animation->IntAttribute( "x" ), animation->IntAttribute( "y" ) );
std::list<object>::iterator i = q_object.begin();
bool varadded = false;
while( i != q_object.end() )
{
if( i->depth > depth )
{
q_object.insert( i, new_object );
varadded = true;
i = q_object.end();
}
else ++i;
}
if( varadded == false ) q_object.push_back( new_object );
}
}
The animation class loads its own image, which is kept inside the class (not the best idea, I know). The class itself is moved into the list.
EDIT: I just tried setting the sprites to a globally-declared image, and it failed as well.