class FlxExtendedMouseSprite
package flixel.addons.display
extends FlxSprite › FlxObject › FlxBasic
An enhanced FlxSprite that is capable of receiving mouse clicks, being dragged and thrown, mouse springs, gravity and other useful things
Note: This class will be deprecated soon, It's quite outdated and unmaintained.
Constructor
new(X:Float = 0, Y:Float = 0, ?SimpleGraphic:Null<FlxGraphicAsset>)
Creates a white 8x8 square FlxExtendedSprite at the specified position. Optionally can load a simple, one-frame graphic instead.
Parameters:
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!). |
Variables
boundsRect:FlxRect
An FlxRect region of the game world within which the sprite is restricted during mouse drag
frictionX:Float
Determines how quickly the Sprite come to rest on the walls if the sprite has x gravity enabled
frictionY:Float
Determines how quickly the Sprite come to rest on the ground if the sprite has y gravity enabled
read onlymouseOver: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.
mousePressedCallback:MouseCallback
Function called when the mouse is pressed down on this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int
mouseReleasedCallback:MouseCallback
Function called when the mouse is released from this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int
mouseStartDragCallback:MouseCallback
Function called when the mouse starts to drag this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int
mouseStopDragCallback:MouseCallback
Function called when the mouse stops dragging this sprite. Function is passed these parameters: obj:FlxExtendedSprite, x:int, y:int
read onlymouseX:Int
Returns how many horizontal pixels the mouse pointer is inside this sprite from the top left corner. Returns -1 if outside.
read onlymouseY:Int
Returns how many vertical pixels the mouse pointer is inside this sprite from the top left corner. Returns -1 if outside.
priorityID:Int
Used by FlxMouseControl when multiple sprites overlap and register clicks, and you need to determine which sprite has priority
springOffsetX:Int = 0
By default the spring attaches to the top left of the sprite. To change this location provide an x offset (in pixels)
springOffsetY:Int = 0
By default the spring attaches to the top left of the sprite. To change this location provide a y offset (in pixels)
springOnPressed:Bool = true
Will the Mouse Spring be active always (false) or only when pressed (true)
read onlyspringX:Int
The spring x coordinate in game world space. Consists of sprite.x + springOffsetX
read onlyspringY:Int
The spring y coordinate in game world space. Consists of sprite.y + springOffsetY
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)
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)
Methods
inlinedisableMouseClicks():Void
Stops this sprite from checking for mouse clicks and clears any set callbacks
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.
disableMouseThrow():Void
Stops this sprite from being able to be thrown. If it currently has velocity this is NOT removed from it.
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
Parameters:
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) |
enableMouseDrag(LockCenter:Bool = false, PixelPerfect:Bool = false, AlphaThreshold:Int = 255, ?BoundsRect:FlxRect, ?BoundsSprite:FlxSprite):Void
Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
Parameters:
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 |
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.
Parameters:
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 |
enableMouseSpring(onPressed:Bool = true, retainVelocity:Bool = false, tension:Float = 0.1, friction:Float = 0.95, gravity:Float = 0.0, ?offset:FlxPoint):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)
Parameters:
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
enableMouseThrow(FactorX:Int, FactorY:Int):Void
Make this Sprite throwable by the mouse. The sprite is thrown only when the mouse button is released.
Parameters:
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+ |
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
mousePressedHandler():Void
Called by FlxMouseControl when this sprite is clicked. Should not usually be called directly.
mouseReleasedHandler():Void
Called by FlxMouseControl when this sprite is released from a click. Should not usually be called directly.
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!
Parameters:
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 |
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.
Parameters:
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) |
startDrag():Void
Called by FlxMouseControl when Mouse Drag starts on this Sprite. Should not usually be called directly.