Flixel Power Tools FlxExtendedSprite

Back to the Flixel Power Tools

Sprites in Flixel are already quite powerful, but I needed more! So the FlxExtendedSprite class was born. These extended a normal FlxSprite, so anything you can do with that you can do with this. But it also adds some much needed functionality into the mix, including: The ability to click the sprite! Complete with a click counter, mouse down and mouse up callbacks. You can also drag the sprite. Dragging can be restricted to a single axis, or a rectangular block of the game world, and can snap to a grid either during drag or on release.

Extended Sprites are also able to sort themselves in real-time, meaning you can have z-indexed sprites, and should a bunch of them overlap you define the sort criteria to control which one of them receives the “mouse click” event (maybe it’s based on their y coordinate? Or the built-in priority ID). Mouse clicks are either within the bounding box of the sprite, or can be pixel perfect with configurable alpha tolerance level too.

They can also be thrown or have gravity (or both!) for some lovely combinations of effects. And finally there is a built-in spring, so it can be connected to the mouse via a spring. This spring can be set to only be active on mouse-drag, or always be there. The spring constraints are under your control for some interesting effects. There is even a mini-game in the Test Suite showing off the speed of the mouse click responses.

Screen Shots

Code Example

Recent Flixel Power Tool Posts

  1. Flixel Power Tools v1.9 Released
  2. Flixel Power Tools v1.8 Released - Let's get clicky
  3. Flixel Power Tools v1.7 - Kaboom!
  4. Flixel Power Tools v1.6 released including FlxControl
  5. Flixel Power Tools v1.5 - A monster of an update!
  6. FlxScreenGrab and FlxScrollZone added to Flixel Power Tools
  7. Flixel Power Tools v1.3 - Now Flixel 2.5 compatible!
  8. FlxHealthBar added to Flixel Power Tools

4 Responses

Leave a comment
  • Dylan
    July 30th 2011 at 10:52 am

    Looks like there’s a bug when a dragged sprite collides with two surfaces of a tilemap and will push/slip through the second surface it contacts with. Great library!

  • July 30th 2011 at 8:10 pm

    It’s not really a bug – what is happening is that the mouse has got so far away from the sprite that it tunnels through the tile map. Flixel doesn’t have any CCD support which would resolve this – so the only way to get around this is to use the mouseZone rect and keep updating the rect so it’s centered around the sprite. The rect would need to be sized correctly so it’s 1 tiles width. Basically form a deadzone around the sprite. So what happens is if the mouse leaves the deadzone (because the sprite collides with a wall) the drag is disabled automatically. Not ideal, but the only real choice atm.

  • October 31st 2012 at 6:08 pm

    Hi there,

    I seem to be running into an issue with enableMouseClicks() – it seems that when I create an extended sprite and then enable mouse clicks for it (like in your Mouse Clicks demo in Demo Suite) it makes the entire thing break.

    I know it’s that particular function, because it works fine if I comment it out.

    Any help would be great.

  • October 31st 2012 at 6:10 pm

    You know what, I’m an idiot. I missed out on enabling the FlxMouseControl plugin.


Make yourself heard