1
\$\begingroup\$

I'm using flixel and flixer power tools which contains a FlxButtonPlus class that allows me to load 2 FlxSprite as each button state, the problem is that FlxSprite requires a Class a its source but I would like to have a single spritesheet for all my buttons and call each one from there, rather than having a bunch of pngs for every button and every state.

Any idea on how to do that?

\$\endgroup\$
1
\$\begingroup\$

You can have one (or a few) PNG sprite sheet and use it for multiple different sprites. You'll need to create the sprite object and use loadGraphic(graphic,true) to load the sprite sheet. "animated" must be true; if it's false the entire image will be one static frame. "graphic" is the embedded PNG of type Class

You'll have to put them all in one horizontal row and each frame will need to be the same width and height as all the others. Ideally frames should be square, but you can specify rectangular frames. Then you can use frame = value where value is the index of the frame you want to use for static images.

You can also do addAnimation("name", [1, 2, 3], 29) to create named animations that you can play back with play("name"). That said, it is probably a good idea to still do separate sprite sheets for animated sprites.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.