0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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); 
\$\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.