FlxReplay during normal gameplay



  • I have a bunch of objects in my game that are controlled via FlxReplays. and they are preventing me from using the mouse and keyboard, I know that's supposed to be the point, but is there a way to play the next frame of replay and then revert 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. Im 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 replay and use for that object, leaving the main player's inputs unaffected?



  • This post is deleted!


  • figured it out on stack overflow I can just extend FlxReplay to manipulate different inputs and use those to control the objects while FlxG.mouse and keys control my player.

    package com.geokureli.testbed.misc;
    
    import openfl.display.Sprite;
    import flixel.input.keyboard.FlxKeyboard;
    import flixel.system.replay.FrameRecord;
    import flixel.input.mouse.FlxMouse;
    import flixel.FlxG;
    import flixel.system.replay.FlxReplay;
    import flixel.ui.FlxButton;
    import com.geokureli.krakel.State;
    
    /**
     * ...
     * @author George
     */
    class TestAny extends State {
        
        var replay:Replay;
        
        public function new() { super(); }
        
        override public function create():Void {
            super.create();
            
            replay = new Replay(new FlxKeyboard(), new ReplayMouse());
            var replayData:String = "0\n";
            var i:Int = 200;
            var order = [2,1,-1,0];
            for (i in 0 ... 1000){
                
                replayData += '${i}km100,100,${order[i % 4]},0\n';
            }
            trace(replayData);
            replay.load(replayData);
            
            add(new FlxButton(50, 30, "test", function(){ trace("click"); }));
        }
        
        override public function update(elapsed:Float):Void {
        
            if (replay != null) {
                
                replay.playNextFrame();
                
                if (replay.mouse.justPressed)
                    trace("replay click");
                    
                if (replay.finished) {
    			
                    replay = null;
                    trace("done");
                }
            }
            
            super.update(elapsed);
        }
    }
    
    class Replay extends FlxReplay {
        
        public var keys (default, null):FlxKeyboard;
        public var mouse(default, null):FlxMouse;
        
        public function new (keys:FlxKeyboard, mouse:FlxMouse) {
            super();
            
            this.keys = keys;
            this.mouse = mouse;
        }
    
        override public function playNextFrame():Void {
            
            if (_marker >= frameCount) {
                
                finished = true;
                return;
            }
            
            if (_frames[_marker].frame != frame++)
                return;
            
            var fr:FrameRecord = _frames[_marker++];
            
            if (fr.keys  != null) keys .playback(fr.keys );
            if (fr.mouse != null) mouse.playback(fr.mouse);
        }
    }
    
    class ReplayMouse extends FlxMouse {
        
        public function new() { super(new Sprite()); }
    }
    

    side question: why does FlxMouse have a private constructor?


Log in to reply
 

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