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
- 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.
// Our players space ship
player = new FlxSprite(160, 200, AssetsRegistry.invaderPNG);
// Creates our weapon. We'll call it "lazer" and link it to the x/y coordinates of the player sprite
lazer = new FlxWeapon("lazer", player, "x", "y");
// Tell the weapon to create 50 bullets using the bulletPNG image.
// The 5 value is the x offset, which makes the bullet fire from the tip of the players ship.
lazer.makeImageBullet(50, AssetsRegistry.bulletPNG, 5);
// Sets the direction and speed the bullets will be fired in
Recent Flixel Power Tool Posts
- Flixel Power Tools v1.9 Released
- Flixel Power Tools v1.8 Released - Let's get clicky
- Flixel Power Tools v1.7 - Kaboom!
- Flixel Power Tools v1.6 released including FlxControl
- Flixel Power Tools v1.5 - A monster of an update!
- FlxScreenGrab and FlxScrollZone added to Flixel Power Tools
- Flixel Power Tools v1.3 - Now Flixel 2.5 compatible!
- FlxHealthBar added to Flixel Power Tools
9 ResponsesLeave a comment
Make yourself heard
All about Photon Storm and our
HTML5 game development services
Filter our Content
- Cool Links
- Flash Game Dev Tips
- Game Development
- Geek Shopping
- In the Media
- Phaser 3
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 ?
You would create a class that extends FlxWeapon and over-ride the fire method to launch 3 bullets at once.
Thanks for the fast answer, and sorry for my english 😉 You’re stuff is wonderful !
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().
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.
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.
Silvio, it seems FlxWeapon.makeImageBullet() ignores its autoRotate parameter. I’ve modified the code to make it work, try inserting
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.
Also for anyone who was struggling on how to visually add the bullets to your game:
Just add your FlxWeapon.group to your FlxSate.
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
if (FlxG.getPlugin(FlxControl) == null)
lazer = new FlxWeapon(“lazer”, player, “x”, “y”);
lazer.makeImageBullet( 150, Sources.ImgBullet, 4, 10);
FlxControl.player1.setFireButton(“X”, FlxControlHandler.KEYMODE_PRESSED, 250, lazer.fire);
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
laz = new Lazer(player);
what i’m doing wrong?