TouchListener not firing

I have re-written a code from here. to get the touch location( x, y).

Here is my source code.


import com.jme3.font.BitmapText;

import com.jme3.input.event.TouchEvent;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.input.controls.TouchListener;

public class Main extends SimpleApplication implements TouchListener


float posX=0, posY=0;

BitmapText helloText;

public static void main(String[] args) {

Main app = new Main();




public void simpleInitApp() {

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);




guiFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);

helloText = new BitmapText(guiFont, false);


helloText.setText(“Touch on Display”);

helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);




public void simpleUpdate(float tpf) {


helloText.setText( posX + " , " + posY);




public void simpleRender(RenderManager rm) {

//TODO: add render code


public void onTouch(String name, TouchEvent event, float tpf) {

posX = event.getX();

// throw new UnsupportedOperationException(“Not supported yet.”);



Am i written the right code to get touch location ?

You have to register a listener with the inputManager in order to get callbacks for any input event.

In simpleInitApp, put in something like:


inputManager.addMapping(“Touch”, new TouchTrigger(TouchInput.ALL));

inputManager.addListener(this, new String[]{“Touch”});


You probably should review the Hello Input tutorial.

1 Like

May I ask that TouchInput.ALL means all operations except for specific buttons(KEYCODE_BACK)?