class FlxTypedWeapon<TBullet>
package flixel.addons.weapon
import flixel.addons.weapon.FlxWeapon
Static variables
Constructor
new(name:String, bulletFactory:FlxTypedWeapon<TBullet> ‑> TBullet, fireFrom:FlxWeaponFireFrom, speedMode:FlxWeaponSpeedMode)
Creates the FlxWeapon class which will fire your bullets. You should call one of the makeBullet functions to visually create the bullets. Then either use setDirection with fire() or one of the fireAt functions to launch them.
Parameters:
name | The name of your weapon (i.e. "laser" or "shotgun"). For your internal reference really, but could be displayed in-game. |
---|---|
bulletFactory | FlxWeapon uses this factory function to actually create a bullet |
fireFrom | enum that describes the weapon firing position, for Example Parent, Position. |
speedMode | enum that describes the bullets speed mode, for Example Velocity, Acceleration. |
Variables
bounds:FlxRect
When a bullet goes outside of this bounds it will be automatically killed, freeing it up for firing again. TODO - Needs testing with a scrolling map (when not using single screen display)
bulletElasticity:Float = 0
The elasticity of the fired bullet controls how much it rebounds off collision surfaces. Between 0 and 1 (0 being no rebound, 1 being 100% force rebound). Set to zero to disable.
bulletLifeSpan:FlxBounds<Float>
The lifespan of the bullet, given in seconds. The bullet will be killed once it passes this lifespan, if still alive and in bounds.
read onlyfirePosition:FlxBounds<FlxPoint>
If parent is null, the Weapon will fire from a fixed x/y position on the screen, like in the game Missile Command.
fireRate:Int = 0
The delay in milliseconds (ms) between which each bullet is fired, set to zero to clear. By default there is no rate, as it can be controlled by FlxControl.setFireButton. However if you are firing using the mouse you may wish to set a firing rate.
read onlygroup:FlxTypedGroup<TBullet>
The FlxGroup into which all the bullets for this weapon are drawn. This should be added to your display and collision checked against it.
read onlypositionOffset:FlxPoint
When the bullet is fired if you need to offset it on the x/y axis, for example to line it up with the "nose" of a space ship, set the amount here (positive or negative)
rotateBulletTowardsTarget:Bool = false
Auto set the bullet angle when firing, such that it faces towards the target
useParentDirection:Bool
If true, when fired the bullet direction is based on parent sprites facing value (up/down/left/right)
Methods
inlinebulletsOverlap(ObjectOrGroup:FlxBasic, ?NotifyCallBack:(FlxObject, FlxObject) ‑> Void, SkipParent:Bool = true):Void
Checks to see if the bullets are overlapping the specified object or group
Parameters:
ObjectOrGroup | The group or object to check if bullets collide |
---|---|
NotifyCallBack | A function that will get called if a bullet overlaps an object |
SkipParent | Don't trigger collision notifies with the parent of this object |
inlinefireAtMouse():Bool
Fires a bullet (if one is available) at the mouse coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate.
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
inlinefireAtPosition(X:Int, Y:Int):Bool
Fires a bullet (if one is available) at the given x/y coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate.
Parameters:
X | The x coordinate (in game world pixels) to fire at |
---|---|
Y | The y coordinate (in game world pixels) to fire at |
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
inlinefireAtTarget(Target:FlxSprite):Bool
Fires a bullet (if one is available) at the given targets x/y coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate.
Parameters:
Target | The FlxSprite you wish to fire the bullet at |
---|
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
fireAtTouch(?Touch:FlxTouch):Bool
Fires a bullet (if one is available) at the FlxTouch coordinates, using the speed set in setBulletSpeed and the rate set in setFireRate.
Parameters:
Touch | The FlxTouch object to fire at, if null use the first available one |
---|
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
inlinefireFromAngle(angle:FlxBounds<Float>):Bool
Fires a bullet (if one is available) based on the given angle
Parameters:
angle | The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) |
---|
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
inlinefireFromParentAngle(angle:FlxBounds<Float>):Bool
Fires a bullet (if one is available) based on the angle of the Weapons parent
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
inlinefireFromParentFacing(angleNoise:FlxBounds<Float>):Bool
Fires a bullet (if one is available) based on the facing (UP/DOWN/LEFT/RIGHT) of the Weapons parent
Returns:
True if a bullet was fired or false if one wasn't available. A reference to the bullet fired is stored in FlxWeapon.currentBullet.
rotatePoints(point:FlxPoint, origin:FlxPoint, angle:Float):FlxPoint
Calculates the new position for a point rotated around another point
Parameters:
point | The to be rotated point |
---|---|
origin | The to be rotated around point. usually the origin of the parent flxsprite |
angle | the current angle from of the origin. usually the parent angle. |
Returns:
The new rotated Point
setPostFireCallback(?Callback:() ‑> Void, ?Sound:FlxSound):Void
Sets a post-fire callback function and sound. These are played immediately after the bullet is fired.
Parameters:
Callback | The function to call |
---|---|
Sound | An FlxSound to play |
setPreFireCallback(?Callback:() ‑> Void, ?Sound:FlxSound):Void
Sets a pre-fire callback function and sound. These are played immediately before the bullet is fired.
Parameters:
Callback | The function to call |
---|---|
Sound | A FlxSound to play |