Virtual Buttons Documentation - How to use?

I’m trying to take advantage of Virtual Buttons…

The link is here: http://doc.xenko.com/latest/en/manual/input/virtual-buttons.html

The guide says “Assign a function to MyButton” but it’s unclear how to actually do that.

At the bottom it shows this:

public override void Update() {
float button = Input.GetVirtualButton(0, “MyButton”);
}


Is the float a value I can bounce into the Input class? How can I bind this to an Input.IsKeyPressed? Can’t figure it out, any help is appreciated.

PS. I love this engine, I’m going to for reals release 3 games on it–keep up the good work.
-Jarmo

It depends on the VirtualButton. In general for things that are “buttons” i.e. Keyboard keys the value is either 0.0f or 1.0f. So you could do something like:

if(Input.GetVirtualButton(0,"MyButton") > 0.0f) // or possibly != 0.0f
{
    //Do something
}

Other VirtualButtons like VirtualButton.Mouse.PositionX would be the same as using Input.Mouse.Position.X. So you will have to look at documentation etc. (and possibly code in gitlab) to work out what does what. But You can do some interesting stuff like:

// Create a new VirtualButtonConfigSet if none exists. 
Input.VirtualButtonConfigSet = Input.VirtualButtonConfigSet ?? new VirtualButtonConfigSet();

Input.VirtualButtonConfigSet.Add(new VirtualButtonConfig()
{
    new VirtualButtonBinding("Horizontal", new VirtualButtonTwoWay(VirtualButton.Keyboard.Left,VirtualButton.Keyboard.Right)),
    new VirtualButtonBinding("Vertical", new VirtualButtonTwoWay(VirtualButton.Keyboard.Down,VirtualButton.Keyboard.Up)),
});

//.....
float Speed = 10.0f;
//...
var direction = new Vector3(Input.GetVirtualButton(0, "Horizontal"), Input.GetVirtualButton(0, "Vertical"), 0);

direction.Normalize();

float deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;
this.Entity.Transform.Position += direction * Speed * deltaTime;
//...

I did try this exactly with no luck but I will give it another go tonight.

Thanks for your response!

I will also incorporate the mouse renderer in the future. One question I had on the mouse renderer was regarding the Draw method and when it was called. It did not appear to be called in the update method so is this executed by being in the renderer list?

I will post a video of my progress in a couple weeks, I’m focusing on network code at the present, namely authoritative state.