Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Gatleos

Pages: [1]
1
SFML projects / darkFunction Sprite Editor loader for SFML
« on: January 29, 2014, 10:12:19 pm »
Download it here.

So I recently found a very useful sprite animation editor called darkFunction Editor. It outputs .sprite and .anim files, and several game engines already have frameworks to load these. SFML doesn't yet, so I decided to bite the bullet and make my own.

It's still very much a work in progress, but so far it loads in the xml .sprite and .anim files with pugixml (which is included). It arranges and draws the sprites with pixel-perfect accuracy, and supports flipping and rotation. I've just added basic animation support, but it doesn't take the cell delay or number of loops into account yet.

Hello World
After adding the files to your project, put something like this in your initialization:
sf::Texture tex;
AnimationInfo ainfo;// contains static animation info
SpriteHandler shandler;// maintains and draws the animation
pugi::xml_document ani;
pugi::xml_document spr;
// load the .anim file
ani.load_file("myanimfile.anim");
// loadSheetName returns the name of the sheet so you can load the correct .sprite file
spr.load_file( ainfo.loadSheetName(ani).c_str() );
ainfo.load(ani, spr);
tex.loadFromFile( ainfo.getImageName() );// AnimationInfo::load saved the texture name for us
ainfo.setTexture(tex);
shandler.setAnimationInfo(ainfo);// set the animation data for the SpriteHandler to draw from
shandler.setAnim(0);// set the current animation from the list
shandler.t.translate(100.0, 100.0);// move it over so you can see it

Then just put this in your main loop:
shandler.update();// loops through cells in the current animation
shandler.draw(render_window);// pass in any render target

There's an example image, .sprite and .anim you can download from the darkFunction site (here) to test it with. Feel free to test it out, offer suggestions, and express revulsion at my code design. But keep in mind it's not finished yet. Thanks!

Pages: [1]
anything