Hello, I’m making a game on android and have a little problem. Nifty GUI Button doesn’t react to any touch input (like taping with two fingers in one time and so on) and doesn’t invoke method it should. Maybe there are any other commands instead of onClick? Here are some code related with Nifty GUI:
Main:
//...
private void initNiftyGui(){
niftyDisplay = new NiftyJmeDisplay(StaticAssetManager.getAssetManager(),
inputManager,
audioRenderer,
guiViewPort);
guiViewPort.addProcessor(niftyDisplay);
}
Lifecycle:
public class TestLifecycle extends Lifecycle implements ScreenController {
private CameraControl cameraControl;
private GUI gui;
//...
public TestLifecycle(SimpleApplication simpleApplication) {
super(simpleApplication);
loadModels();
cameraControl = new CameraControl(simpleApplication.getCamera(), simpleApplication.getInputManager());
Level level = LevelFactory.getLevel(0);
gameLogicProcessor = new GameLogicProcessor();
worldMap = new WorldMap(level.getWorldObjects());
mapRenderer = new MapRenderer(simpleApplication.getRootNode(), 1f, simpleApplication.getCamera());
gui = new GUI(simpleApplication.getGuiNode());
worldLight = new WorldLight(simpleApplication.getRootNode(), new Vector3f(-1f, -2f, 0.1f)/*simpleApplication.getCamera().getDirection()*/);
mapRenderer.addTerrain(new Terrain(5));
selectToolManager = new SelectToolManager(worldMap, mapRenderer, simpleApplication.getRootNode(), cameraControl);
worldMap.addObserver(mapRenderer);
worldMap.addObserver(gameLogicProcessor);
worldMap.addObserver(selectToolManager);
//....
@Override
public void update() {
mapRenderer.onUpdate();
worldLight.onUpdate();
worldMap.onUpdate();
gui.onUpdate();
gameLogicProcessor.onUpdate();
cameraControl.onUpdate();
selectToolManager.onUpdate();
}
//...
private void niftyTest(){
Element niftyElement = gui.nifty.getCurrentScreen().findElementByName("text");
niftyElement.getRenderer(TextRenderer.class).setText("124");
}
public void addTree(){
Tree tree = new Tree(getCenterPoint(1));
worldMap.put(tree);
}
Gui:
public class GUI {
private Node guiNode;
public static final int CLICK_OFFSET = 5;
public Nifty nifty;
public GUI(Node guiNode){
this.guiNode = guiNode;
nifty = Main.niftyDisplay.getNifty();
nifty.fromXml("Interface/HelloJme.xml", "start");
}
public void onUpdate(){
}
}
And XML file:
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="start" controller="tk.ubublik.redivansion.gamelogic.lifecycle.TestLifecycle">
<layer id="background" childLayout="center">
</layer>
<layer id="foreground" childLayout="vertical">
<panel id="buttontest" color="#FF0F" height="25%" width="25%" align="left" valign="top" childLayout="center">
<control name="button" label="Add tree" id="addTree" height="100%" width="100%" align="center" valign="center" visibleToMouse="true" >
<interact onClick="niftyTest()"/></control>
</panel>
<panel id="text" backgroundColor="#5728" height="25%" width="25%" align="left" valign="top" childLayout="center">
<text name="text" text="My Cool Game" font="Interface/Fonts/Default.fnt" width="100%" height="100%" />
</panel>
</layer>
</screen>
The button and text appears on android device screen, but pressing on the button (with onClick=“niftyTest()” or “addTree()”) gives nothing.
Also, one another question — when I place finger on a panel (with text or button) and move it, the camera is moving too. Is it possible to make camera stop while user is interacting with GUI?
Thanks!