George Kurelic
George Kurelic

Reputation: 105

FlxReplay during normal gameplay

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?

Upvotes: 2

Views: 75

Answers (1)

Vincent Blanchet
Vincent Blanchet

Reputation: 36

I think I have done something like this for Ludum Dare 38. I separated the replay from its dependency to FlxG controls. Check the MyReplay class:

https://github.com/boorik/Ludum38/blob/master/source/MyReplay.hx

This way I can interact with the game without interfering with NPC replays. In my game you play with all the characters of the game to record their replay. While recording one replay, other recorded replays are played on their target NPC.

You can have a look to the result here:

http://games.boorik.com/ludumdare38/

I hope I have understood your issue and this helps.

Upvotes: 2

Related Questions