HelloInput Example didn't work

Hey :slight_smile:

i tried your example HelloInput - but it doesn’t worked. The box will not move by pressing the keys k and l or pause when pressing p

I also copy the text from your site, but with the same result.
Do you know what wents wrong ?!

Post the entire code your using. This could be because you are running one of the earlier Hello World examples by accident in main (), or running the wrong file (press shift + f6 on the file, and make sure main () is instantiating the correct class).

Otherwise maybe you press p first? which doesn’t really pause, just prevents j, k and space from doing anything.

1 Like

Also, have you tried adding printlns to see what’s happening or done any other basic debugging of the problem?

<cite>@wezrule said:</cite>

Post the entire code your using. This could be because you are running one of the earlier Hello World examples by accident in main (), or running the wrong file (press shift + f6 on the file, and make sure main () is instantiating the correct class).

Otherwise maybe you press p first? which doesn’t really pause, just prevents j, k and space from doing anything.

Thanks for the tip - with shift + F6 it works…

Here is the entire code:

[java]
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package jme3test;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.ColorRGBA;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;

/** Sample 5 - how to map keys and mousebuttons to actions */
public class HelloInput extends SimpleApplication {

public static void main(String[] args) {
HelloInput app = new HelloInput();
app.start();
}
protected Geometry player;
Boolean isRunning=true;

@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
player = new Geometry(“Player”, b);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”, ColorRGBA.Blue);
player.setMaterial(mat);
rootNode.attachChild(player);
initKeys(); // load my custom keybinding
}

/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
// You can map one or several inputs to one named action
inputManager.addMapping(“Pause”, new KeyTrigger(KeyInput.KEY_P));
inputManager.addMapping(“Left”, new KeyTrigger(KeyInput.KEY_J));
inputManager.addMapping(“Right”, new KeyTrigger(KeyInput.KEY_K));
inputManager.addMapping(“Rotate”, new KeyTrigger(KeyInput.KEY_SPACE),
new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
// Add the names to the action listener.
inputManager.addListener(actionListener,“Pause”);
inputManager.addListener(analogListener,“Left”, “Right”, “Rotate”);

}

private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“Pause”) && !keyPressed) {
isRunning = !isRunning;
}
}
};

private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (isRunning) {
if (name.equals(“Rotate”)) {
player.rotate(0, valuespeed, 0);
}
if (name.equals(“Right”)) {
Vector3f v = player.getLocalTranslation();
player.setLocalTranslation(v.x + value
speed, v.y, v.z);
}
if (name.equals(“Left”)) {
Vector3f v = player.getLocalTranslation();
player.setLocalTranslation(v.x - value*speed, v.y, v.z);
}
} else {
System.out.println(“Press P to unpause.”);
}
}
};
}

[/java]

yep looks fine. Its because your project is configured to a different main. Pressing F6 will use your project’s configured main, while shift + f6, executes the current file’s main.

Thanks for the tip :slight_smile:

F6 didnt work, but under Projectproperties -> Run -> select Main Class you can select the right class - this works for me :slight_smile: -thank you so much!
(And sorry for the double post)