class flixel.addons.nape.FlxNapeSprite extends FlxSprite
Available on all platforms
FlxNapeSprite consists of an FlxSprite with a physics body. * During the simulation, the sprite follows the physics body position and rotation. * * By default, a rectangular physics body is created upon construction in createRectangularBody(). * * @author TiagoLr ( ~~~ProG4mr~~~ )
Instance Fields
function new(?X:Float = 0, ?Y:Float = 0, ?SimpleGraphic:Dynamic = null, ?CreateRectangularBody:Bool = true, ?EnablePhysics:Bool = true):Void
Creates an FlxNapeSprite with an optional physics body (body). * At each step, the physics are updated, and so is the position and rotation of the sprite * to match the bodys position and rotation values. * By default a physics body with rectangle shape will be created around your sprite graphics. * You can override this functionality and add a premade body of your own (see addPremadeBody). * *
X | The initial X position of the sprite. * |
Y | The initial Y position of the sprite. * |
SimpleGraphic | The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!). * |
CreateRectangularBody | Whether to create a rectangular body for this sprite (use false if you want to add a custom body). * |
EnablePhysics | Whether to enable physics simulation on the rectangular body (only relevant if CreateRectangularBody == true). |
function addPremadeBody(NewBody:Body):Void
Makes it easier to add a physics body of your own to this sprite by setting it's position, * space and material for you. * *
NewBody | The new physics body replacing the old one. |
function createCircularBody(?Radius:Float = 16, ?_Type:BodyType = null):Void
Creates a circular physics body for this sprite. * *
Radius | The radius of the circle-shaped body - 16 by default * |
_Type | The BodyType of the physics body. Optional, DYNAMIC by default. |
function createRectangularBody(?Width:Float = 0, ?Height:Float = 0, ?_Type:BodyType = null):Void
Default method to create the physics body used by this sprite in shape of a rectangle. * Override this method to create your own physics body! * The width and height used are based on the size of sprite graphics if 0 is passed. * Call this method after calling makeGraphics() or loadGraphic() to update the body size. * *
Width | The width of the rectangle. 0 = frameWidth * |
Height | The height of the rectangle. 0 = frameHeight * |
_Type | The BodyType of the physics body. Optional, DYNAMIC by default. |
WARNING: This will remove this sprite entirely. Use kill() if you * want to disable it temporarily only and reset() it later to revive it. * Override this function to null out variables or manually call * destroy() on class members if necessary. * Don't forget to call super.destroy()!
Handy function for "killing" game objects. * Default behavior is to flag them as nonexistent AND dead.
Handy function for bringing game objects "back to life". Just sets alive and exists back to true. * In practice, this function is most often called by FlxObject.reset().
function setBodyMaterial(?Elasticity:Float = 1, ?DynamicFriction:Float = 0.2f, ?StaticFriction:Float = 0.4f, ?Density:Float = 1, ?RotationFriction:Float = 0.001f):Void
Shortcut method to set/change the physics body material. * *
Elasticity | Elasticity of material. * |
DynamicFriction | Coeffecient of dynamic friction for material. * |
StaticFriction | Coeffecient of static friction for material. * |
Density | Density of this Material. * |
RotationFriction | Coeffecient of rolling friction for circle interactions. |
function setDrag(?LinearDrag:Float = 1, ?AngularDrag:Float = 1):Void
Nape requires fluid spaces to add empty space linear drag and angular drag. * This provides a simple drag alternative. * Set any values to linearDrag or angularDrag to activate this feature for this object. * *
LinearDrag | Typical value 0.96 (1 = no drag). * |
AngularDrag | Typical value 0.96 (1 = no drag); |