Provides mouse event detection for FlxObject and FlxSprite (pixel-perfect for those). To use it, initialize the manager and register objects / sprites.

FlxG.plugins.add(new FlxMouseEventManager());
var object = new FlxObject();
FlxMouseEventManager.add(
	 object, onMouseDown, onMouseUp, onMouseOver, onMouseOut);

Or simply add a new object and this plugin will initialize itself:

FlxMouseEventManager.add(
	 object, onMouseDown, onMouseUp, onMouseOver, onMouseOut);

Also implement the callbacks with the object's type as parameters:

function onMouseDown(object:FlxObject) {}
function onMouseUp(object:FlxObject) {}
function onMouseOver(object:FlxObject) {}
function onMouseOut(object:FlxObject) {}

Static variables

@:value(500)staticmaxDoubleClickDelay:Int = 500

The maximum amount of time between two clicks that is considered a double click, in milliseconds.

Available since

4.4.0

.

Static methods

@:value({ PixelPerfect : true, MouseEnabled : true, MouseChildren : false })staticadd<T>(Object:T, ?OnMouseDown:T ‑> Void, ?OnMouseUp:T ‑> Void, ?OnMouseOver:T ‑> Void, ?OnMouseOut:T ‑> Void, MouseChildren:Bool = false, MouseEnabled:Bool = true, PixelPerfect:Bool = true, ?MouseButtons:Array<FlxMouseButtonID>):T

Adds an object to the FlxMouseEventManager registry. Automatically initializes the plugin.

Parameters:

OnMouseDown

Callback when mouse is pressed down over this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

OnMouseUp

Callback when mouse is released over this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

OnMouseOver

Callback when mouse is this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

OnMouseOut

Callback when mouse moves out of this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

MouseChildren

If true, other objects overlapped by this will still receive mouse events.

MouseEnabled

If true, this object will receive mouse events.

PixelPerfect

If true, the collision check will be pixel-perfect. Only works for FlxSprites.

MouseButtons

The mouse buttons that can trigger callbacks. Left only by default.

staticinlineinit():Void

As alternative you can call FlxMouseEventManager.init().

staticisObjectMouseChildren<T>(Object:T):Bool

Checks if an object allows mouseChildren.

staticisObjectMouseEnabled<T>(Object:T):Bool

Checks if a registered object is mouseEnabled.

staticremove<T>(Object:T):T

Removes a registered object from the registry.

staticremoveAll():Void

Removes all registered objects from the registry.

staticreorder():Void

Reorders the registered objects, using the current object drawing order. This should be called if you alter the draw/update order of a registered object, That is, if you alter the position of a registered object inside its FlxGroup. It may also be called if the objects are not registered by the same order they are added to FlxGroup.

staticsetMouseClickCallback<T>(Object:T, OnMouseClick:T ‑> Void):Void

Sets the mouseClick callback associated with an object.

Parameters:

OnMouseClick

Callback when mouse is pressed and released over this object. Must have Object as argument - e.g. onMouseClick(object:FlxObject).

Available since

4.4.0

.

staticsetMouseDoubleClickCallback<T>(Object:T, OnMouseDoubleClick:T ‑> Void):Void

Sets the mouseDoubleClick callback associated with an object.

Parameters:

OnMouseDoubleClick

Callback when mouse is pressed and released over this object twice. Must have Object as argument - e.g. onMouseDoubleClick(object:FlxObject).

Available since

4.4.0

.

staticsetMouseDownCallback<T>(Object:T, OnMouseDown:T ‑> Void):Void

Sets the mouseDown callback associated with an object.

Parameters:

OnMouseDown

Callback when mouse is pressed down over this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

staticsetMouseMoveCallback<T>(Object:T, OnMouseMove:T ‑> Void):Void

Sets the mouseMove callback associated with an object.

Parameters:

OnMouseMove

Callback when the mouse is moved while over this object. Must have Object as argument - e.g. onMouseMove(object:FlxObject).

Available since

4.4.0

.

staticsetMouseOutCallback<T>(Object:T, OnMouseOut:T ‑> Void):Void

Sets the mouseOut callback associated with an object.

Parameters:

OnMouseOver

Callback when mouse is moved out of this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

staticsetMouseOverCallback<T>(Object:T, OnMouseOver:T ‑> Void):Void

Sets the mouseOver callback associated with an object.

Parameters:

OnMouseOver

Callback when mouse is over this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

staticsetMouseUpCallback<T>(Object:T, OnMouseUp:T ‑> Void):Void

Sets the mouseUp callback associated with an object.

Parameters:

OnMouseUp

Callback when mouse is released over this object. Must have Object as argument - e.g. onMouseDown(object:FlxObject).

staticsetMouseWheelCallback<T>(Object:T, OnMouseWheel:T ‑> Void):Void

Sets the mouseWheel callback associated with an object.

Parameters:

OnMouseWheel

Callback when the mouse wheel is moved while over this object. Must have Object as argument - e.g. onMouseWheel(object:FlxObject).

Available since

4.4.0

.

staticsetObjectMouseButtons<T>(object:T, mouseButtons:Array<FlxMouseButtonID>):Void

Parameters:

MouseButtons

The mouse buttons that can trigger callbacks. Left only by default.

staticsetObjectMouseChildren<T>(Object:T, MouseChildren:Bool):Void

Enables/disables mouseChildren for an object.

Parameters:

MouseChildren

Whether this object will allow other overlapping object to receive mouse events.

staticsetObjectMouseEnabled<T>(Object:T, MouseEnabled:Bool):Void

Enables/disables mouse behavior for an object.

Parameters:

MouseEnabled

Whether this object will be tested for mouse events.

Constructor

new()

Methods

Inherited Variables

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets ot sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxBasic

draw():Void

Override this function to control how the object is drawn. Doing so is rarely necessary, but can be very useful.

kill():Void

Handy function for "killing" game objects. Use reset() to revive them. Default behavior is to flag them as nonexistent AND dead. However, if you want the "corpse" to remain in the game, like to animate an effect or whatever, you should override this, setting only alive to false, and leaving exists true.

revive():Void

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