Skip to content

Commit

Permalink
FlxMouseEventManager: properly reset on state switches
Browse files Browse the repository at this point in the history
The previous hack of checking for destroyed sprites during update() led to some issues. Now it behaves more like FlxTweenManager / FlxTimerManager, registering a stateSwitched callback.
closes #1986
  • Loading branch information
Gama11 committed May 20, 2017
1 parent 481ad70 commit 045fc70
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions flixel/input/mouse/FlxMouseEventManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FlxMouseEventManager extends FlxBasic
* Must have Object as argument - e.g. onMouseDown(object:FlxObject).
* @param OnMouseOut Callback when mouse moves out of this object.
* Must have Object as argument - e.g. onMouseDown(object:FlxObject).
* @param MouseChildren If true, other objects overlaped by this will still receive mouse events.
* @param MouseChildren If true, other objects overlapped by this will still receive mouse events.
* @param MouseEnabled If true, this object will receive mouse events.
* @param PixelPerfect If true, the collision check will be pixel-perfect. Only works for FlxSprites.
* @param MouseButtons The mouse buttons that can trigger callbacks. Left only by default.
Expand All @@ -82,7 +82,7 @@ class FlxMouseEventManager extends FlxBasic
}

/**
* Removes a registerd object from the registry.
* Removes a registered object from the registry.
*/
public static function remove<T:FlxObject>(Object:T):T
{
Expand Down Expand Up @@ -321,12 +321,15 @@ class FlxMouseEventManager extends FlxBasic
}
_registeredObjects = new Array<ObjectMouseData<FlxObject>>();
_mouseOverObjects = new Array<ObjectMouseData<FlxObject>>();

FlxG.signals.stateSwitched.add(removeAll);
}

override public function destroy():Void
{
clearRegistry();
_point = FlxDestroyUtil.put(_point);
FlxG.signals.stateSwitched.remove(removeAll);
super.destroy();
}

Expand All @@ -338,13 +341,6 @@ class FlxMouseEventManager extends FlxBasic

for (reg in _registeredObjects)
{
// Sprite destroyed check.

This comment has been minimized.

Copy link
@MSGhero

MSGhero May 20, 2017

Member

👍

if (reg.object.acceleration == null)
{
remove(reg.object);
continue;
}

if (!reg.object.alive || !reg.object.exists || !reg.object.visible || !reg.mouseEnabled)
{
continue;
Expand Down

0 comments on commit 045fc70

Please sign in to comment.