Can't get onTouch to execute

Hi, I need to work with multiple finger inputs and I need to know their position always. So ActionListener is rather worthless in this case.
So I thought I’d use
[java]@Override
public void onTouch(String name, TouchEvent evt, float tpf)
{[/java]
Only problem is that it’s never executed.
Nomather how much I move my fingers on the screen, nothing prints.
And the only gui that’s running is an empty screen which does’nt contain any panels or layers at all.
I’v even attached the game instance as a listener using MainGame.getInput().addListener(MainActivity.thais,“main”); //thais = this

So idk what more to do to make this work… Am I missing something?

onTouch works fine, but you have to implement TouchListener. Below is a simple example Main class and LogCat.

[java]
public class Main extends SimpleApplication implements ActionListener, AnalogListener, TouchListener, RawInputListener {
private static final Logger logger = Logger.getLogger(Main.class.getName());

public static void main(String[] args) {
    Main app = new Main();

    AppSettings settings = new AppSettings(true);
    settings.setResolution(960, 540); // phone landscape mode

// settings.setResolution(540, 960); // phone portrait mode
app.setSettings(settings);
app.setShowSettings(false);
app.setDisplayFps(true);
// app.setDisplayStatView(false);

    app.start();
}

@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    Geometry geom = new Geometry("Box", b);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    TextureKey texKey = new TextureKey("Textures/Sky/Lagoon/lagoon_west.jpg", true);
    Texture tex = assetManager.loadTexture(texKey);
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);

    rootNode.attachChild(geom);

    String[] mappings = {
        "Main_Button_Left",
        "Main_Button_Middle",
        "Main_Button_Right",
        "Main_Axis_X_Plus",
        "Main_Axis_X_Minus",
        "Main_Axis_Y_Plus",
        "Main_Axis_Y_Minus",
        "Main_Axis_Wheel_Plus",
        "Main_Axis_Wheel_Minus",
        "Main_Touch_All",
    };

    inputManager.addMapping("Main_Button_Left", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("Main_Button_Middle", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addMapping("Main_Button_Right", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("Main_Axis_X_Plus", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping("Main_Axis_X_Minus", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("Main_Axis_Y_Plus", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("Main_Axis_Y_Minus", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("Main_Axis_Wheel_Plus", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    inputManager.addMapping("Main_Axis_Wheel_Minus", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    inputManager.addMapping("Main_Touch_All", new TouchTrigger(TouchInput.ALL));

    inputManager.addListener(this, mappings);
    inputManager.addRawInputListener(this);
}

@Override
public void simpleUpdate(float tpf) {
    //TODO: add update code
}

@Override
public void simpleRender(RenderManager rm) {
    //TODO: add render code
}

public void onAction(String mapping, boolean pressed, float tpf) {
    logger.log(Level.INFO, "onAction mapping: {0}, pressed: {1}, tpf: {2}",
            new Object[]{mapping, pressed, tpf});
}

public void onAnalog(String mapping, float value, float tpf) {
    logger.log(Level.INFO, "onAnalog mapping: {0}, value: {1}, tpf: {2}",
            new Object[]{mapping, value, tpf});
}

public void onTouch(String mapping, TouchEvent te, float tpf) {
    logger.log(Level.INFO, "onTouch mapping: {0}, pointerId: {1}, type: {2}, tpf: {3}, X: {4}, Y: {5}",
            new Object[]{mapping, te.getPointerId(), te.getType(), tpf, te.getX(), te.getY()});
}

@Override
public void stop(boolean waitFor) {
    super.stop(waitFor);
    long heapMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    logger.log(Level.INFO, "Total heap memory held: {0}kb", heapMem / 1024);
}

@Override
public void destroy() {
    super.destroy();
    long heapMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    logger.log(Level.INFO, "Total heap memory held: {0}kb", heapMem / 1024);
}

public void beginInput() {

}

public void endInput() {

}

public void onJoyAxisEvent(JoyAxisEvent jae) {

}

public void onJoyButtonEvent(JoyButtonEvent jbe) {

}

public void onMouseMotionEvent(MouseMotionEvent mme) {

}

public void onMouseButtonEvent(MouseButtonEvent mbe) {
    logger.log(Level.INFO, "onMouseButtonEvent pointerId: {0}, pressed: {1}, X: {2}, Y: {3}",
            new Object[]{mbe.getButtonIndex(), mbe.isPressed(), mbe.getX(), mbe.getY()});
}

public void onKeyEvent(KeyInputEvent kie) {

}

public void onTouchEvent(TouchEvent te) {
    logger.log(Level.INFO, "onTouchEvent pointerId: {0}, type: {1}, X: {2}, Y: {3}",
            new Object[]{te.getPointerId(), te.getType(), te.getX(), te.getY()});
}

}
[/java]

[java]
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: DOWN, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onMouseButtonEvent pointerId: 0, pressed: true, X: 720, Y: 132
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: DOWN, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAction mapping: Main_Button_Left, pressed: true, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.019
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.015, tpf: 0.015
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.014, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 724.727, Y: 142.765
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 724.727, Y: 142.765
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 727.878, Y: 151.483
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 727.878, Y: 151.483
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Plus, value: 0.003, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.009, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 728.928, Y: 155.298
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.018, X: 728.928, Y: 155.298
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Plus, value: 0.001, tpf: 0.018
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.004, tpf: 0.018
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.018, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.018
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 732.079, Y: 164.016
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 732.079, Y: 164.016
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Plus, value: 0.004, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.009, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 733.129, Y: 173.824
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.018, X: 733.129, Y: 173.824
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Plus, value: 0.001, tpf: 0.018
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.009, tpf: 0.018
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.018, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.018
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 732.079, Y: 183.088
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 732.079, Y: 183.088
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Minus, value: 0.001, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.01, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 734.179, Y: 192.351
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 734.179, Y: 192.351
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Plus, value: 0.002, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.009, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 733.129, Y: 202.159
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 733.129, Y: 202.159
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_X_Minus, value: 0.001, tpf: 0.017
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.01, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 733.129, Y: 209.788
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 733.129, Y: 209.788
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.007, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 733.129, Y: 211.423
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 733.129, Y: 214.692
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 733.129, Y: 211.423
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.002, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.017, X: 733.129, Y: 214.692
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.003, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.017, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.017
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: MOVE, X: 733.129, Y: 223.956
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: SCROLL, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: MOVE, tpf: 0.024, X: 733.129, Y: 223.956
INFO Main 8:16:58 AM onAnalog mapping: Main_Axis_Y_Plus, value: 0.009, tpf: 0.024
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: SCROLL, tpf: 0.024, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onAnalog mapping: Main_Button_Left, value: 0.017, tpf: 0.024
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: UP, X: 733.129, Y: 223.956
INFO Main 8:16:58 AM onMouseButtonEvent pointerId: 0, pressed: false, X: 733, Y: 223
INFO Main 8:16:58 AM onTouchEvent pointerId: 0, type: FLING, X: 720.525, Y: 132.412
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: UP, tpf: 0.017, X: 733.129, Y: 223.956
INFO Main 8:16:58 AM onAction mapping: Main_Button_Left, pressed: false, tpf: 0.017
INFO Main 8:16:58 AM onTouch mapping: Main_Touch_All, pointerId: 0, type: FLING, tpf: 0.017, X: 720.525, Y: 132.412
[/java]

3 Likes

Thanks alot man!!
This helped me alot :smiley:

I just tried it and it seems to work great! Thanks :slight_smile: