Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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