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);

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.


1 Answer 1


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); 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .