Problem with input manager mapping

Hi,

I have a character and I want to impart a user input to it which makes it turn when user presses key T.



Here is what I have done…



inputManager.addMapping(“turn”,

new Trigger[]{new KeyTrigger(KeyInput.KEY_T)});



inputManager.addListener(actionListener, new String[]{“shoot”,“Walk”,“push”,“turn”});



and in onAction method I have added code as follows:



if (name.equals(“turn”) && !keyPressed){

if (!channel.getAnimationName().equals(“turn”)){

player.rotate(0,FastMath.PI,0);

//channel.setAnim(“Dodge”, 0.50f);

//channel.setLoopMode(LoopMode.Loop);

}

}



But unfortunately nothing happens when I press key T.



Please help.



Manish

the first line looks a little weird, try using :



[java]

inputManager.addMapping(“turn”, new KeyTrigger(KeyInput.KEY_T));

[/java]



The way I see it, the problem could come from 2 places, either your mapping has not been setup correctly, so pressing T is being ignored by the engine, or the mapping is correct and your rotation code is not working as you expect.



You will need to start debugging to figure out what is not working, the simplest way start to do this is by using:



[java]System.out.println(“debug messages go here, and the value of some variable is:”+variableName);[/java]



This will print messages to the console for you. You will find yourself using this debugging technique over and over, so get used to it :slight_smile:



I would start by adding the following inside your onAction method :



[java]

System.out.println("onAction has been called with the action: "+name);

if (name.equals(“turn”) && !keyPressed){

if (!channel.getAnimationName().equals(“turn”)){

[/java]



after you add that code and run your app, when you press T, if the mapping has been setup correctly, you should see somewhere in the output panel (probably towards the bottom):

onAction has been called with the action: turn

(you could always try pressing some of the other keys that you know work to test this message.)



If your mapping for T is correctly set-up, it means the problem lies with your turning code.



Add a few debug statements and see if you can’t figure out exactly what is not working, eg:



[java]

System.out.println("the animation name is "+channel.getAnimationName());

if (!channel.getAnimationName().equals(“turn”)){

[/java]

1 Like

Thanks theToucher.



Manish