Flixel Power Tools FlxWeapon

Back to the Flixel Power Tools

FlxWeapon is a comprehensive weapon manager for any game that involves shooting! It handles the creation, pooling and re-use of bullets. It supports:

  • Angled Bullets
  • Bullet Velocity and Acceleration
  • Sounds
  • Callbacks
  • Fire at the Mouse
  • Fire from the Mouse
  • Fire from a parent Sprite
  • Fire at a target Sprite
  • Fire from a fixed position
  • Fire to a fixed position
  • Set the firing rate (in real-time)
  • Bullet Gravity (!)

Use it FlxControl for a really powerful combo. Weapons can be stacked onto a single player, so there’s no reason they couldn’t be firing several of them at the same time.

Screen Shot

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

9 Responses

Leave a comment
  • Notsu
    January 17th 2012 at 10:07 pm

    I have experienced migrating my project’s weapons ( a shoot ’em up ) to this FlxWeapon class, but I was wondering have could I manage weapon that must cast several bullets ( like bi/tri-directionnal bullets ) , how can we do it with your class ?

  • January 17th 2012 at 10:32 pm

    You would create a class that extends FlxWeapon and over-ride the fire method to launch 3 bullets at once.

  • Notsu
    January 17th 2012 at 11:38 pm

    Thanks for the fast answer, and sorry for my english 😉 You’re stuff is wonderful !

  • Steven
    March 15th 2012 at 3:39 pm

    Hi,
    if I want to change the animation of a bullet I have to create a new weapon is that right? I found no “changeBulletAnimation()” method or something like that. Changing or setting the animation is just possible with makeAnimatedBullet().

  • March 15th 2012 at 4:54 pm

    You’ve got direct access to the Bullet, so you could change the animation in it that way – rather than re-creating a brand new animated bullet.

  • Silvio
    February 4th 2013 at 4:56 pm

    I was wondering if there’s a way so the bullet turns according to the angle of mouse. I have my weapon shoot arrows and they aren’t turning.

  • robro
    June 26th 2013 at 9:33 pm

    Silvio, it seems FlxWeapon.makeImageBullet() ignores its autoRotate parameter. I’ve modified the code to make it work, try inserting
    if (rotateToAngle)
    {
    currentBullet.angle = angle;
    }
    at the very end of FlxWeapon.runFire(), right where it says “bulletsFired++”. I did a few more things, so I’m not quite sure this will work out of the box, but it should give you a start.

    Good luck!

  • Rafael Collado
    September 3rd 2013 at 5:51 pm

    Also for anyone who was struggling on how to visually add the bullets to your game:

    Just add your FlxWeapon.group to your FlxSate.
    cheers! :]

  • Fabi
    December 9th 2013 at 3:21 pm

    I’ve tried to make lazer class, then extend it with FlxWeapon, so it looks like that:
    public class Lazer extends FlxWeapon
    {
    public var lazer:FlxWeapon;

    public function Lazer(player:FlxObject):void
    {
    super(?);

    if (FlxG.getPlugin(FlxControl) == null)
    {
    FlxG.addPlugin(new FlxControl);
    }

    lazer = new FlxWeapon(“lazer”, player, “x”, “y”);
    lazer.makeImageBullet( 150, Sources.ImgBullet, 4, 10);
    lazer.setBulletLifeSpan(1000);
    lazer.setBulletBounds(FlxG.worldBounds);
    FlxControl.player1.setFireButton(“X”, FlxControlHandler.KEYMODE_PRESSED, 250, lazer.fire);
    lazer.setBulletLifeSpan(1000);
    lazer.setBulletDirection(FlxWeapon.BULLET_RIGHT, 200);
    }

    i don’t really know what to put in super() but whatever i put in there, game start but in framerate like 4fps, when i press “X” there is sound of fire, but no bullets,in Playstate create() where i have my test map i add

    private var laz:Lazer
    create()
    laz = new Lazer(player);
    add(laz.group);

    what i’m doing wrong?

Make yourself heard