How I remove the esc exit

How I can remove the exit by esc key,and when I press esc,to use nifty gui.Then how I exit from application(I want to use a button using nifty,any way to kill the app)?

app.getInputManager().deleteMapping( SimpleApplication.INPUT_MAPPING_EXIT );



If you are running a nightly build.



Otherwise, you have to guess the input mapping name. Better to update.

2 Likes

So,what I need to have ticked between:

*Base platform alpha

*jMonkeyEngine SDK Nightly

*jMonkeyEngine SDK Stable

*jMonkeyEngine SDK User Contributions

?

First,second and fourth?

Now I have first,third and fourth.

Nightly should be good enough. So you should have that constant.

Lol, this topic reminds me of an old classic:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/removing-esc-key-to-exit/

Where should I put that?

This is what I’ve tried(line 68):

[java]package mygame;

import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.input.controls.Trigger;

import com.jme3.light.DirectionalLight;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.renderer.RenderManager;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;

import com.jme3.shadow.BasicShadowRenderer;

import com.jme3.texture.Texture;

import com.jme3.util.SkyFactory;

/**

  • test
  • @author normenhansen

    /

    public class MainGUI extends SimpleApplication implements ScreenController{

    Nifty nifty;

    Screen screen;

    boolean start = false;

    NiftyJmeDisplay niftyDisplay;

    Geometry player;

    MainGUI app;

    public static void main(String[] args) {

    MainGUI app = new MainGUI();

    app.start();

    }

    private BulletAppState bulletAppState;

    @Override

    public void simpleInitApp() {

    // disable the fly cam

    flyCam.setEnabled(false);

    niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager,

    audioRenderer, guiViewPort);

    nifty = niftyDisplay.getNifty();

    nifty.fromXml(“Interface/GUI.xml”, “start”, this);

    // attach the nifty display to the gui view port as a processor

    guiViewPort.addProcessor(niftyDisplay);

    }

    public void LoadMainGame(){

    bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);

    // bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    if (settings.getRenderer().startsWith(“LWJGL”)) {

    BasicShadowRenderer bsr = new BasicShadowRenderer(assetManager, 512);

    bsr.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());

    viewPort.addProcessor(bsr);

    }

    cam.setFrustumFar(150f);

    flyCam.setMoveSpeed(10);

    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());

    // setupFloor();

    buildSky();

    DirectionalLight dl = new DirectionalLight();

    dl.setDirection(new Vector3f(-0.5f, -1f, -0.3f).normalizeLocal());

    rootNode.addLight(dl);

    dl = new DirectionalLight();

    dl.setDirection(new Vector3f(0.5f, -0.1f, 0.3f).normalizeLocal());

    rootNode.addLight(dl);

    app.getInputManager().deleteMapping( SimpleApplication.INPUT_MAPPING_EXIT );

    }

    public void start2() {

    nifty.exit();

    System.out.println(“Welcome”);

    LoadMainGame();

    inputManager.setCursorVisible(false);

    flyCam.setEnabled(true);

    }

    @Override

    public void simpleUpdate(float tpf) {

    if(start)

    {

    System.out.println(“No”);

    player.rotate(0, 2
    tpf, 0);

    }

    }

    @Override

    public void simpleRender(RenderManager rm) {

    //TODO: add render code

    }

    public void bind(Nifty nifty, Screen screen) {

    this.nifty = nifty;

    this.screen = screen;

    }

    public void onStartScreen() {

    }

    public void onEndScreen() {

    }

    private void buildSky() {

    Texture west = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_west.jpg”);

    Texture east = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_east.jpg”);

    Texture north = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_north.jpg”);

    Texture south = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_south.jpg”);

    Texture up = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_up.jpg”);

    Texture down = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_down.jpg”);

    Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down);

    rootNode.attachChild(sky);

    }

    public void options(){

    this.nifty.setAlternateKeyForNextLoadXml(“fade”);

    this.nifty.fromXml(“Interface/options.xml”, “start”);

    }

    public void onSettingsOK() {

    this.nifty.setAlternateKeyForNextLoadXml(“fade”);

    this.nifty.fromXml(“Interface/GUI.xml”, “start”);

    }

    public void exit() {

    }

    }[/java]

    But don’t work,and it kills all other mouse and keyboard controls.

Well, most of the stuff you do in the constructor should really be in simpleInit(). Maybe try moving the delete mapping there. Though that single delete mapping should not affect anything else. Still, do it before you setup nifty or anything else. Maybe there is something else going on in InputManager.

Already tried that:

NFO: Child (Statistics View) attached to this node (Gui Node)

09.07.2011 21:17:26 com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at mygame.MainGUI.simpleInitApp(MainGUI.java:44)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:124)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:200)

at java.lang.Thread.run(Thread.java:662)



Now that line is the first line in simpleInitApp().

You have a lot of weird things going on compounding your issues.



First:

MainGUI app;



a) you do not need it because you already are app everywhere except main() you can just use “this.” or just refer to your variables and methods directly.



b) in main, you aren’t actually setting that anyway because you have your own locally scoped MainGUI app.



Remove the instance variable MainGUI app; on line 31.



Anywhere you use “app.” just remove the “app.” part.

1 Like

Thanks,now works.

I have another problem with keys:

actionListener has private access in com.jme3.app.SimpleApplication



This is the code:

[java] public void setupKeys(){

inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));

inputManager.addListener(actionListener, new String[]{"Pause"});

}

public void onAction(String binding, boolean value, float tpf) {

if (binding.equals("Pause")) {

pauseTheGame();

}

}[/java]

Whats the problem? Without the mapping they wont be triggered. You just go and implement your own listeners.

1 Like

Make you own action listener. You don’t want to reuse something else’s behavior.



Instead of trying to call your own method make your own anonymous inner class that calls it or just does what the method does.

1 Like

I have another problem:

[java]public void setupKeys(){

inputManager.addMapping(“Pause”, new KeyTrigger(KeyInput.KEY_ESCAPE));

inputManager.addListener(actionListener, new String[]{“Pause”});

}

private ActionListener actionListener = new ActionListener() {

public void onAction(String name, boolean keyPressed, float tpf) {

/** TODO */

if (name.equals(“Pause”)&&!keyPressed) {

isRunning = !isRunning;

// else if …

}

if (isRunning) {

mouseInput.setCursorVisible(false);

} else {

pause();

mouseInput.setCursorVisible(true);

}

}

};[/java]

I pressed esc,it appears a new menu(using nifty gui),but I don’t know how to make to disappear that menu when I pressed esc again.

Edit: found,nifty.removeScreen(" ");