My conclusion (IMHO) is that nifty-gui does not support multi-touch.
If you want to verify that, here is my example:
Tap and hold LEFT button
stdout: onAction: Left = true
Tap and hold JUMP button
stdout: onAction: Left = false
no further events after releasing the buttons.
The left button receives a mouse focus lost event and triggers onRelease.
The jump button triggers no events at all. You have to touch it again.
Tested on iOS with my patch for multi-touch. (PR will follow.)
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.RawInputListener;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.TouchListener;
import com.jme3.input.controls.TouchTrigger;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.input.event.JoyButtonEvent;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.input.event.TouchEvent;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import de.lessvoid.nifty.screen.DefaultScreenController;
/**
* Test to show that nifty-gui currently does not support multi-touch!
*/
public class Main extends SimpleApplication implements TouchListener {
private NiftyMenu menu;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
// NOTE: if flyCam is not disabled, nifty will not send interactOnClick events!
flyCam.setEnabled(false);
setDisplayFps(false);
setDisplayStatView(false);
// touch listener is not required to receive nifty-gui onClick/onRelease, but it is just good for debugging
inputManager.addMapping("Touch", new TouchTrigger(0));
inputManager.addListener(this, "Touch");
menu = new NiftyMenu(this, new MenuController());
menu.gotoScreen("HUDScreen_ID");
//mouseInput.setCursorVisible(true);
//inputManager.setSimulateMouse(false); // no effect
}
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
}
public class MenuController extends DefaultScreenController
{
public void onHUDAction(String binding, String value)
{
boolean b = value.equals("true");
System.out.println("onHUDAction: " + binding + " = " + value);
if (binding.equals("Left"))
{
}
else if (binding.equals("Jump"))
{
}
}
}
@Override
public void onTouch(String name, TouchEvent e, float tpf) {
float x = e.getX();
float y = e.getY();
int id = e.getPointerId();
System.out.println(id + ": " + x + "," + y);
}
}