My question sounds pretty simple but awfully, I couldn't find much information on the internet.

How can I draw a circle in my FlxSprite?

I couldn't find much information about drawing geometric objects or the usage of classic graphics API in Flixel.


You can access the underlying BitmapData of a FlxSprite by using sprite.pixels or sprite.framePixels. You can then use BitmapData's drawing methods for simple things. If you need to draw a circle, you'll probably want to make a DisplayObject like a proper Sprite, draw on it using Graphics, and then use the BitmapData's draw() function to draw it onto the FlxSprite.

Note that this goes against Flixel's intended paradigm. If you're doing this once at the start of the game, or very rarely, it will work just fine to generate sprites procedurally. However, doing this every frame (e.g. in the render() code) will make probably make Flixel much slower. If you know ahead of time what sort of circle you need, you might want to just load the circle as a sprite from a file.


Your Answer

