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.

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.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
add comment

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.