I have a bunch of NPC objects in my game that are controlled via FlxReplay
instances. and they are preventing me from using the mouse and keyboard to control the hero directly. Is there a way to play the next frame of the FlxReplay
, read the inputs and then revert the input to what they were before?
Example:
package com.geokureli.testbed;
import flixel.FlxG;
import flixel.FlxState;
import flixel.system.replay.FlxReplay;
import flixel.ui.FlxButton;
class TestBed extends FlxState {
var replay:FlxReplay;
public function new() { super(); }
override public function create():Void {
super.create();
replay = new FlxReplay();
replay.load("0\n0km100,100,0,0\n100km178,240,2,0\n101km178,240,1,0\n102km178,240,-1,0\n103km178,240,0,0\n");
add(new FlxButton(50, 30, "test", function(){ trace("click"); }));
}
override public function update(elapsed:Float):Void {
if (replay != null) {
replay.playNextFrame();
if (FlxG.mouse.justPressed)
trace("replay click");
if (replay.finished) {
replay = null;
trace("done");
}
}
// --- REVERT INPUTS HERE
super.update(elapsed);
}
}
I'm unable to click the button while the replay is active. I'm wondering if I could swap out the FlxG.inputs
and FlxG.keys
/mouse
during all of the replays and then swap back the originals after. Or if I can target specific inputs for the replay to use, leaving the main player's inputs unaffected?