Issue with FlxMouseEventManager, FlxSprite and FlxSubState



  • Hi ! I'm new to HaxeFlixel (even Haxe) and I have an issue with FlxMouseEventManager, FlxSprite and FlxSubState.
    The sprite of the parent's Substate keep going to fire event even when I am on the SubState.
    I want to know how I can disable the parent's sprite while I am on the substate or if I can do that on another way.
    I'll past a minimal code below

    There is the code of the parent substate :

    class WorldMapState extends FlxSubState {
    	private var place:Place;
    
    	override public function create():Void {
    		super.create();
    		persistentDraw = false;
    		persistentUpdate = false;
    		place = new Place(300, 200);
    		add(place);
    		FlxMouseEventManager.add(place, onMouseUp);
    	}
    
    	override public function update(elapsed:Float):Void {
    		super.update(elapsed);
    	}
    
    	private function onMouseUp(sprite:flixel.FlxSprite):Void {
    		Sys.println("onMouseUp");
    		openSubState(new TestState());
    	}
    }
    

    And the code of the TestState :

    class TestState extends FlxSubState {
    	private var place:Place;
    
    	override public function create():Void {
    		super.create();
    		place = new Place(100, 300);
    		add(place);
    		FlxMouseEventManager.add(place, onMouseUp);
    	}
    
    	override public function update(elapsed:Float):Void {
    		super.update(elapsed);
    	}
    
    	private function onMouseUp(sprite:flixel.FlxSprite):Void {
    		close();
    	}
    }
    

    I hope that you can help me.
    Thanks !



  • Posted in https://github.com/HaxeFlixel/flixel-ui/issues/191#issuecomment-256723928:

    Also ran into this. In my case, it was due to FlxMouseEventManager remaining active even though the parent state's update method was not being called.

    Workaround: in your parent state, do something like this:

     private var mouseEventManager: FlxBasic;
    
     override public function openSubState(subState: FlxSubState) {
       mouseEventManager = FlxG.plugins.get(FlxMouseEventManager);
       FlxG.plugins.remove(mouseEventManager);
       super.openSubState(subState);
     }
    
     override public function closeSubState() {
       super.closeSubState();
       FlxG.plugins.add(mouseEventManager);
     }
    


  • @DleanJeans Thank you for the answer !
    However, I don't know why but this line FlxG.plugins.add(mouseEventManager); doesn't seem to work, so I've change it with FlxMouseEventManager.add(place, onMouseUp); and now it works perfectly !



Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.