Nez icon indicating copy to clipboard operation
Nez copied to clipboard

Add ability to simulate VirtualInput activation

Open fuzzypixelz opened this issue 2 years ago • 5 comments

This changes the four VirtualInput classes to include a Simulate(...) method that allows (you guessed it) simulating an input.

The implementation uses the Update() method to keep the input activated for one frame, with the help of a simulationStep counter.

This may be pretty hacky, so I'm open to reimplementing it in a cleaner way if the maintainers so desire.

fuzzypixelz avatar Sep 19 '21 01:09 fuzzypixelz

Why not just subclass a custom Node? you could implement the same functionality.

redthing1 avatar Sep 19 '21 16:09 redthing1

Yeah, @redthing1 may be right on this one. Now that I see the code it’s a bit more intrusive than my initial thoughts about it ;) Maybe instead swap to a subclass for each: SimulatedVirtualAxis, SimulatedVirtualButton, etc.

prime31 avatar Sep 19 '21 19:09 prime31

Ya, I did exactly this in my project. If you want the code let me know, but it's pretty simple and straightforward to implement yourself.

redthing1 avatar Sep 19 '21 20:09 redthing1

I guessed as much because to be honest I wasn't satisfied with it myself. @redthing1 Yes I would like to see the code please. I'll open a new PR once I get the chance (tomorrow is a Monday™!)

fuzzypixelz avatar Sep 19 '21 20:09 fuzzypixelz

Very very simple, here's my virtual joystick:

public class LogicJoystick : Nez.VirtualJoystick.Node {
            public override Vector2 Value => LogicValue;

            public Vector2 LogicValue { get; set; }
        }

redthing1 avatar Sep 19 '21 20:09 redthing1