class flixel.addons.display.FlxExtendedSprite extends FlxSprite

Available on all platforms

An enhanced FlxSprite that is capable of receiving mouse clicks, being dragged and thrown, mouse springs, gravity and other useful things * * @link http://www.photonstorm.com * @author Richard Davey / Photon Storm

Instance Fields

var boundsRect:FlxRect

An FlxRect region of the game world within which the sprite is restricted during mouse drag

var boundsSprite:FlxSprite

An FlxSprite the bounds of which this sprite is restricted during mouse drag

var clickable:Bool

Is this sprite allowed to be clicked?

var clicks:Int

The number of clicks this item has received. Usually you'd only set it to zero.

var draggable:Bool

Is this sprite allowed to be dragged by the mouse? true = yes, false = no

var frictionX:Float

Determines how quickly the Sprite come to rest on the walls if the sprite has x gravity enabled

var frictionY:Float

Determines how quickly the Sprite come to rest on the ground if the sprite has y gravity enabled

var gravityX:Int

The x axis gravity influence

var gravityY:Int

The y axis gravity influence

var hasGravity:Bool

Does this sprite have gravity applied to it?

var hasMouseSpring:Bool

Is this sprite using a mouse spring?

var isDragged:Bool

Is this sprite being dragged by the mouse or not?

var isPressed:Bool

If the mouse currently pressed down on this sprite?

var mouseOver:Bool

Return true if the mouse is over this Sprite, otherwise false. Only takes the Sprites bounding box into consideration and does not check if there * are other sprites potentially on-top of this one. Check the value of this.isPressed if you need to know if the mouse is currently clicked on this sprite.

var mousePressedCallback:MouseCallback

Function called when the mouse is pressed down on this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int

var mouseReleasedCallback:MouseCallback

Function called when the mouse is released from this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int

var mouseSpring:FlxMouseSpring

The MouseSpring object which is used to tie this sprite to the mouse

var mouseStartDragCallback:MouseCallback

Function called when the mouse starts to drag this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int

var mouseStopDragCallback:MouseCallback

Function called when the mouse stops dragging this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int

var mouseX:Int

Returns how many horizontal pixels the mouse pointer is inside this sprite from the top left corner. Returns -1 if outside.

var mouseY:Int

Returns how many vertical pixels the mouse pointer is inside this sprite from the top left corner. Returns -1 if outside.

var point:FlxPoint

A FlxPoint consisting of this sprites world x/y coordinates

var priorityID:Int

Used by FlxMouseControl when multiple sprites overlap and register clicks, and you need to determine which sprite has priority

var rect:FlxRect

Returns a FlxRect consisting of the bounds of this Sprite.

var springOffsetX:Int

By default the spring attaches to the top left of the sprite. To change this location provide an x offset (in pixels)

var springOffsetY:Int

By default the spring attaches to the top left of the sprite. To change this location provide a y offset (in pixels)

var springOnPressed:Bool

Will the Mouse Spring be active always (false) or only when pressed (true)

var springX:Int

The spring x coordinate in game world space. Consists of sprite.x + springOffsetX

var springY:Int

The spring y coordinate in game world space. Consists of sprite.y + springOffsetY

var throwable:Bool

Is this sprite allowed to be thrown?

var toleranceX:Float

If the velocity.x of this sprite falls between zero and this amount, then the sprite will come to a halt (have velocity.x set to zero)

var toleranceY:Float

If the velocity.y of this sprite falls between zero and this amount, then the sprite will come to a halt (have velocity.y set to zero)

function new(?X:Float = 0, ?Y:Float = 0, ?SimpleGraphic:Dynamic = null):Void

Creates a white 8x8 square FlxExtendedSprite at the specified position. * Optionally can load a simple, one-frame graphic instead. * *

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!).

function disableMouseClicks():Void

Stops this sprite from checking for mouse clicks and clears any set callbacks

function disableMouseDrag():Void

Stops this sprite from being able to be dragged. If it is currently the target of * an active drag it will be stopped immediately. Also disables any set callbacks.

function disableMouseSnap():Void

Stops the sprite from snapping to a grid during drag or release.

function disableMouseSpring():Void

Stops the sprite to mouse spring from being active

function disableMouseThrow():Void

Stops this sprite from being able to be thrown. If it currently has velocity this is NOT removed from it.

function enableMouseClicks(OnRelease:Bool, ?PixelPerfect:Bool = false, ?AlphaThreshold:Int = 255):Void

Allow this Sprite to receive mouse clicks, the total number of times this sprite is clicked is stored in this.clicks * You can add callbacks via mousePressedCallback and mouseReleasedCallback * *

OnRelease

Register the click when the mouse is pressed down (false) or when it's released (true). Note that callbacks still fire regardless of this setting. *

PixelPerfect

If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box. *

AlphaThreshold

If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255)

function enableMouseDrag(?LockCenter:Bool = false, ?PixelPerfect:Bool = false, ?AlphaThreshold:Int = 255, ?BoundsRect:FlxRect = null, ?BoundsSprite:FlxSprite = null):Void

Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback * *

LockCenter

If false the Sprite will drag from where you click it. If true it will center itself to the tip of the mouse pointer. *

PixelPerfect

If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box. *

AlphaThreshold

If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255) *

BoundsRect

If you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere *

BoundsSprite

If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here

function enableMouseSnap(SnapX:Int, SnapY:Int, ?OnDrag:Bool = true, ?OnRelease:Bool = false):Void

Make this Sprite snap to the given grid either during drag or when it's released. * For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels. * *

SnapX

The width of the grid cell in pixels *

SnapY

The height of the grid cell in pixels *

OnDrag

If true the sprite will snap to the grid while being dragged *

OnRelease

If true the sprite will snap to the grid when released

function enableMouseSpring(?OnPressed:Bool = true, ?RetainVelocity:Bool = false, ?Tension:Float = 0.1f, ?Friction:Float = 0.95f, ?Gravity:Float = 0):FlxMouseSpring

Adds a simple spring between the mouse and this Sprite. The spring can be activated either when the mouse is pressed (default), or enabled all the time. * Note that nearly always the Spring will over-ride any other motion setting the sprite has (like velocity or gravity) * *

OnPressed

True if the spring should only be active when the mouse is pressed down on this sprite *

RetainVelocity

True to retain the velocity of the spring when the mouse is released, or false to clear it *

Tension

The tension of the spring, smaller numbers create springs closer to the mouse pointer *

Friction

The friction applied to the spring as it moves *

Gravity

The gravity controls how far "down" the spring hangs (use a negative value for it to hang up!) *

returns

The FlxMouseSpring object if you wish to perform further chaining on it. Also available via FlxExtendedSprite.mouseSpring

function enableMouseThrow(FactorX:Int, FactorY:Int):Void

Make this Sprite throwable by the mouse. The sprite is thrown only when the mouse button is released. * *

FactorX

The sprites velocity is set to FlxMouseControl.speedX * xFactor. Try a value around 50+ *

FactorY

The sprites velocity is set to FlxMouseControl.speedY * yFactor. Try a value around 50+

function flipGravity():Void

Switches the gravity applied to the sprite. If gravity was +400 Y (pulling them down) this will swap it to -400 Y (pulling them up) * To reset call flipGravity again

function mousePressedHandler():Void

Called by FlxMouseControl when this sprite is clicked. Should not usually be called directly.

function mouseReleasedHandler():Void

Called by FlxMouseControl when this sprite is released from a click. Should not usually be called directly.

function setDragLock(?AllowHorizontalDrag:Bool = true, ?AllowVerticalDrag:Bool = true):Void

Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move! * *

AllowHorizontalDrag

To enable the sprite to be dragged horizontally set to true, otherwise false *

AllowVerticalDrag

To enable the sprite to be dragged vertically set to true, otherwise false

function setGravity(GravityX:Int, GravityY:Int, ?FrictionX:Float = 500, ?FrictionY:Float = 500, ?ToleranceX:Float = 10, ?ToleranceY:Float = 10):Void

Gravity can be applied to the sprite, pulling it in any direction. Gravity is given in pixels per second and is applied as acceleration. * If you don't want gravity for a specific direction pass a value of zero. To cancel it entirely pass both values as zero. * *

GravityX

A positive value applies gravity dragging the sprite to the right. A negative value drags the sprite to the left. Zero disables horizontal gravity. *

GravityY

A positive value applies gravity dragging the sprite down. A negative value drags the sprite up. Zero disables vertical gravity. *

FrictionX

The amount of friction applied to the sprite if it hits a wall. Allows it to come to a stop without constantly jittering. *

FrictionY

The amount of friction applied to the sprite if it hits the floor/roof. Allows it to come to a stop without constantly jittering. *

ToleranceX

If the velocity.x of the sprite falls between 0 and +- this value, it is set to stop (velocity.x = 0) *

ToleranceY

If the velocity.y of the sprite falls between 0 and +- this value, it is set to stop (velocity.y = 0)

function startDrag():Void

Called by FlxMouseControl when Mouse Drag starts on this Sprite. Should not usually be called directly.

function stopDrag():Void

Called by FlxMouseControl when Mouse Drag is stopped on this Sprite. Should not usually be called directly.

function update():Void

Core update loop