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.

Is there any way to use an external image/sprite file for the graphic of a FlxSprite instance?

Say I declare my player FlxSprite as follows:

player = new FlxSprite(FlxG.width/2 - 5);
player.makeGraphic(10,12,0xffaa1111);

How could I instead instantiate the FlxSprite using my own spritesheet or image? I have seen others do it in the Flixel demos , and in the featured games.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You want to use the loadGraphic method of FlxSprite, here's an example :

// in your class declarations 
[Embed(source="your.png")] private var yourGraphic:Class;

// in your class code wherever, after you have created an instance
// use true for second parameter if image is a row of sprite frames
player.loadGraphic(yourGraphic, false); 
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.