Game Development Community

Input Maps

by Bruno · in Torque X 2D · 08/17/2007 (3:52 pm) · 2 replies

Hi.,

A slighty problem, i'm having some difficulty understanding how input maps work (global), input maps that are not associated to a particular player.

In the example i'm tryng to do, i have a tilemap, and when i press either the up or down key, i want to change the tilemap texture on it.
The tilemap problems are fixed, i'm on the input part now.

What i have done is the following :

In Game.cs, on the region Private, protected internal methods
right after SceneLoader.Load(blabla)
i build my map logic.

After that is done, i do this :

InputMap map = new InputMap();
int keyboardId = InputManager.Instance.FindDevice("keyboard");
map.BindCommand(keyboardId, (int)Microsoft.Xna.Framework.Input.Keys.Z, ZoomIn,ZoomOut);

I create a new InputMap, keyboardId has the value of 4
map.BindCommand appears to be successful, however the ZoomIn and ZoomOut functions don't do anything.
I believe the setup is wrong here, no idea where.

The ZoomIn and ZoomOut functions, are just like this :


protected void ZoomIn()
{
int Z;
Z = 2;
}

protected void ZoomOut()
{
int x;
x = 0;
}

I have a breakpoint inside them, so i know the key pressing is working or not, but the debugger never breaks there.

Any help is appreciated,
thanks

Bruno

#1
08/18/2007 (4:58 am)
Got it working.,

If someone stops by, i did it like this :


InputMap map = new InputMap();

GarageGames.Torque.Sim.InputMap.Global.BindCommand("keyboard", "Down", ZoomIn, ZoomOut);
GarageGames.Torque.Sim.InputMap.Global.BindCommand("keyboard", "Up", ZoomIn, ZoomOut);
#2
08/18/2007 (12:03 pm)
Your first example was fine. You just have to push the configured input map onto the InputMap stack at the end:

InputManager.Instance.PushInputMap(map).

This way, you can redefine the mappings during the game by just pushing and popping the appropriate maps.