Nifty: how to get mouse events from jme2?

Hello, im running a modified jme2 version to later support multitouch through http://code.google.com/p/multiplicity/ and i am trying to create an roleplaying game. nifty is showing great as the gui, but i cannot click any of the panels with interaction.



The xml sheet works with my own RPGscreencontroller.java and the de.lessvoid.nifty.examples.controls.ControlsDemoMain.class example.



Since i am running my program with “extends SimpleGame” i cannot use LwjglInitHelper, that seems to work wonders with the ControlsDemoMain example.



So i am trying to work around it with :

[java]private static LwjglInputSystem inputSystem;

initInput();

nifty = new Nifty(new RenderDeviceLwjgl(),

new SoundSystem(new SlickSoundDevice()),

inputSystem,

new TimeProvider());[/java]



where initInput() is a copy out of LwjglInitHelper, and is returning true.



my jme game gets all mouse movement and clicks, so i can move the character.



I´ve also tried

[java]JmeNiftyInputSystem jmeNiftyinput = new JmeNiftyInputSystem();

MouseInput.get().addListener(jmeNiftyinput);

KeyInput.get().addListener(jmeNiftyinput);

jmeNiftyinput.bind(nifty);[/java]



and use that as the inputSystem when initiating nifty, but it´s the same problem, nifty does not get any mouse events.

I don’t understand the problem to be honest :smiley:



Can you try to explain it again? Maybe send a bit more code?

Thanks a lot for helping out, I don´t know how much code you need, so i will just post the xml, my screencontroller (which don´t have a lot atm), and the main file, and please tell me if it´s too much and too unorganized, and i will try to create a smaller file that also shows my problem.



The problem is basically that i can use jmonkeyengine perfectly, and nifty shows on top of it, but my problem is that i cannot use the gui with mouse clicks, like nifty does not share mouse events with jmonkeyengine. so, source:



XML sheet:



[java]|?xml version=“1.0” encoding=“UTF-8”?|

|nifty|

|useStyles filename=“nifty-default-styles.xml” /|

|useControls filename=“nifty-default-controls.xml” /|

|screen id=“start” controller=“multiplicity.appgallery.niftytest.RPGscreencontroller”|

|layer id=“hpmanawrapper” childLayout=“absolute”|

|panel x=“368px” y=“268px” height=“15px” width=“64px” backgroundColor="#000" childLayout=“absolute” visibleToMouse=“true”|

|panel x=“2px” y=“2px” height=“5px” width=“60px” backgroundColor="#500" visibleToMouse=“true” /|

|panel x=“2px” y=“8px” height=“5px” width=“60px” backgroundColor="#009" visibleToMouse=“true” /|

|/panel|

|/layer|

|layer id=“layer” childLayout=“center”|

|panel height=“80px” width=“100%” align=“center” valign=“bottom” backgroundColor="#000" childLayout=“absolute” visibleToMouse=“true”|

|panel x=“0px” y=“0px” height=“5px” width=“100%” backgroundColor="#222" visibleToMouse=“true” /|

|image id=“spell1” x=“120px” y=“10px” filename=“data/Magic_button_red.png” width=“70px” height=“70px”|

|interact onClick=“pstest()” /|

|/image|

|image id=“spell2” x=“220px” y=“5px” filename=“data/Magic_button_blue.png” width=“70px” height=“70px”|

|/image|

|image id=“spell3” x=“320px” y=“5px” filename=“data/Magic_button_green.png” width=“70px” height=“70px”|

|/image|

|image id=“spell4” x=“420px” y=“5px” filename=“data/Magic_button_grey.png” width=“70px” height=“70px”|

|/image|

|image id=“spell5” x=“520px” y=“5px” filename=“data/Magic_button_purple.png” width=“70px” height=“70px”|

|/image|

|image id=“spell6” x=“620px” y=“5px” filename=“data/Magic_button_yellow.png” width=“70px” height=“70px”|

|/image|

|panel x=“0px” y=“75px” height=“5px” width=“100%” backgroundColor="#222" visibleToMouse=“true” /|

|/panel|

|/layer|

|/screen|

|/nifty|

[/java]



with the interact on one of the images, I´ve also tried buttons and panels with interact, but same result.

[java] |image id=“spell1” x=“120px” y=“10px” filename=“data/Magic_button_red.png” width=“70px” height=“70px”|

|interact onClick=“pstest()” /|

|/image|[/java]



RPGscreencontroller that should interact with the xml:

[java]package multiplicity.appgallery.niftytest;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;



public class RPGscreencontroller implements ScreenController {

private Nifty nifty;

private Screen screen;



public void bind(Nifty newNifty, Screen newScreen) {

screen = newScreen;

nifty = newNifty;

System.out.println(“bind”);

}

public void onStartScreen() {

System.out.println(“onStartScreen”);

}

public void onEndScreen() {

System.out.println(“onStartScreen”);

}

public void pstest() {

System.out.println(“press test”);

}

}[/java]



which gets the screencontroller from the xml as shown in eclipse when compiling and running



[java]Dec 2, 2010 11:09:33 AM de.lessvoid.nifty.Nifty gotoScreenInternal

INFO: gotoScreenInternal [start]

bind

Dec 2, 2010 11:09:33 AM de.lessvoid.nifty.screen.Screen$StartScreenEndNotify perform

INFO: onStartScreen has ended

onStartScreen

fps: 26[/java]



and finally the main file (its unorganized since its just in progress stuff while i try to learn all this stuff meanwhile) but i think the important stuff should be pretty much up top.



[java]package multiplicity.appgallery.niftytest;



import java.util.ArrayList;

import java.util.Iterator;

import java.util.logging.Level;

import java.util.logging.Logger;



import org.lwjgl.input.Mouse;

import org.lwjgl.opengl.GL11;

import org.lwjgl.opengl.GL13;

import org.lwjgl.util.glu.GLU;



import com.jme.app.SimpleGame;

import com.jme.bounding.BoundingBox;

import com.jme.bounding.BoundingSphere;

import com.jme.curve.CurveController;

import com.jme.curve.PolylineCurve;

import com.jme.image.Texture;

import com.jme.input.InputSystem;

import com.jme.input.KeyInput;

import com.jme.input.MouseInput;

import com.jme.input.joystick.JoystickInput;

import com.jme.intersection.PickData;

import com.jme.intersection.PickResults;

import com.jme.intersection.TrianglePickResults;

import com.jme.light.PointLight;

import com.jme.math.Ray;

import com.jme.math.Vector2f;

import com.jme.math.Vector3f;

import com.jme.scene.shape.Box;

import com.jme.scene.shape.Sphere;

import com.jme.scene.state.BlendState;

import com.jme.scene.state.TextureState;

import com.jme.scene.state.ZBufferState;

import com.jme.system.DisplaySystem;

import com.jme.util.TextureManager;

import com.jme.renderer.ColorRGBA;

import com.jme.renderer.Renderer;

import com.jme.scene.Controller;

import com.jme.scene.Geometry;

import com.jme.scene.Line;

import com.jme.scene.Spatial.LightCombineMode;

import com.jme.scene.Spatial.TextureCombineMode;

import com.jme.scene.TriMesh;

import com.jmex.effects.particles.ParticleFactory;

import com.jmex.effects.particles.ParticleMesh;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.renderer.lwjgl.input.LwjglInputSystem;

import de.lessvoid.nifty.lwjglslick.render.RenderDeviceLwjgl;

import de.lessvoid.nifty.lwjglslick.sound.SlickSoundDevice;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.sound.SoundSystem;

import de.lessvoid.nifty.tools.TimeProvider;



import multiplicity.appgallery.input.JmeNiftyInputSystem;

import multiplicity.appgallery.niftytest.RPGscreencontroller;

import multiplicity.appgallery.niftytest.RPGmonster;

import multiplicity.appgallery.niftytest.RPGspells;



/**

  • TestNiftyGUI is an example implementation of Nifty-GUI 1.1 for JME2

    *
  • @author larynx.ckc@gmx.net

    */

    //public class RPG extends AbstractMultiplicityApp {

    public class RPG_low extends SimpleGame {



    private Vector3f camPos = new Vector3f();

    private Vector3f camDirUp = new Vector3f();

    Sphere walkTo;

    CurveController cc;

    ArrayList monsters;

    RPGspells spell;

    RPGcharacter character;

    TimeProvider time;



    ArrayList collisionWalls;

    Line l;

    Vector3f[] w;

    TextureState ts,ts2,ts4;

    BlendState as1;

    Texture t0,t2,t4;

    RPGscreencontroller rsc;

    float b = 2;

    float hall = 30;

    boolean leftDown;

    boolean moveChar;

    boolean shooting;



    private Nifty nifty = null;

    private Screen screen = null;

    private static LwjglInputSystem inputSystem;



    private int viewportWidth;

    private int viewportHeight;



    private static final Logger logger = Logger.getLogger(RPG_low.class.getName());



    /**
  • Main entry point for the nifty test,

    *
  • @param args

    */

    public static void main(String[] args) {

    try {

    JoystickInput.setProvider(InputSystem.INPUT_SYSTEM_LWJGL);

    } catch (Exception e) {

    logger.logp(Level.SEVERE, RPG_low.class.toString(), “main”, “Exception”, e);

    }

    RPG_low app = new RPG_low();

    // app.setConfigShowMode(ConfigShowMode.AlwaysShow);

    app.start();

    }



    /**
  • builds the scene.

    *
  • @see com.jme.app.SimpleGame#initGame()

    /

    @SuppressWarnings(“deprecation”)

    protected void simpleInitGame() {

    display.setTitle(“Nifty GUI JME2 SimpleGame Test”);

    leftDown = false;

    moveChar = false;

    shooting = false;

    if (!initInput()) {

    System.out.println(“binding initInput() did not work”);

    }

    // Allow mouse to leave the game window (very useful on debugging :slight_smile:

    Mouse.setGrabbed(false);

    // Set mouse cursor

    MouseInput.get().setHardwareCursor(RPG_low.class.getClassLoader().getResource(“jmetest/data/cursor/cursor1.png”));



    setupTexturesAndFloors();

    time = new TimeProvider();

    collisionWalls = new ArrayList();

    monsters = new ArrayList();

    initSpell();

    character = new RPGcharacter(“Fear”, 10, 10, 10);

    rootNode.attachChild(character.getCharacter());



    setupWalls();



    walkTo = new Sphere(“moveball”, 20, 20, 3.0f);

    walkTo.setModelBound(new BoundingBox());

    walkTo.updateModelBound();

    walkTo.setLocalTranslation(0, 0, 0);

    walkTo.setDefaultColor(new ColorRGBA(0.8f, 0.8f, 0.8f, 0.5f));

    rootNode.attachChild(walkTo);



    viewportWidth = DisplaySystem.getDisplaySystem().getWidth();

    viewportHeight = DisplaySystem.getDisplaySystem().getHeight();



    JmeNiftyInputSystem jmeNiftyinput = new JmeNiftyInputSystem();

    MouseInput.get().addListener(jmeNiftyinput);

    KeyInput.get().addListener(jmeNiftyinput);

    jmeNiftyinput.bind(nifty);



    nifty = new Nifty(new RenderDeviceLwjgl(),

    new SoundSystem(new SlickSoundDevice()),

    jmeNiftyinput,

    new TimeProvider());

    nifty.fromXml(“data/rpg.xml”, “start”);



    PointLight light = new PointLight();

    light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );

    light.setAmbient( new ColorRGBA( 200f, 200f, 200f, 1.0f ) );

    light.setLocation( new Vector3f( 0, 0, 0 ) );

    light.setEnabled( true );

    lightState = display.getRenderer().createLightState();

    lightState.setEnabled( true );

    lightState.attach( light );

    rootNode.setRenderState( lightState );



    camPos.set(0.0f, 300.0f, 1.0f);

    camDirUp.set(0.0f, 1.0f, 0.0f);

    cam.setLocation(camPos);

    cam.lookAt(new Vector3f(0.0f,0.0f,0.0f), camDirUp);

    }



    private void mousePick() {

    //Get the mouse position

    Vector2f mousePosition = new Vector2f(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());

    if (mousePosition.getY()<80) {

    return;

    }

    //Create a pick ray from the display

    Ray ray = DisplaySystem.getDisplaySystem().getPickRay(mousePosition, false, new Ray());

    //Find the results (Use which ever method suits your needs

    PickResults results = new TrianglePickResults();

    //PickResults results = new BoundingPickResults();

    //We normally want the distance to see which object is closest

    results.setCheckDistance(true);

    //Get the results from a node

    rootNode.findPick(ray, results);

    //Loop the results

    float distance = 0;

    for (int i = 0; i < results.getNumber(); i++) {

    PickData hit = results.getPickData(i);

    if (hit.getTargetMesh().getName().equalsIgnoreCase(character.getName())) {

    moveChar=true;

    break;

    }

    if (hit.getTargetMesh().getName().equalsIgnoreCase(“floor”)) {

    shooting=true;

    distance = hit.getDistance()+1;

    float calcZ = (float) Math.sqrt(distance
    distance - ray.getOrigin().yray.getOrigin().y);

    float amT,amX,amZ,mX=1,mZ=1;



    amT=Math.abs(ray.getDirection().x)+Math.abs(ray.getDirection().z);

    amX=Math.abs(ray.getDirection().x)/amT;

    amZ=Math.abs(ray.getDirection().z)/amT;



    if (ray.getDirection().z<0) {mZ=-1;}

    if (ray.getDirection().x<0) {mX=-1;}



    float calcT = (float) Math.sqrt(amX
    amX + amZamZ);

    amT=calcZ/calcT;

    amX=amX
    amTmX;

    amZ=amZ
    amTmZ;

    // shootAt(charac.getLocalTranslation().x+(amX), 0, charac.getLocalTranslation().z+(amZ));

    shootAt(amX, 0, amZ);

    break;

    }

    }

    }

    int numBullets;

    private void shootAt(float x, float y, float z) {

    Sphere bullet = new Sphere(“bullet” + numBullets++, 8, 8, spell.getRadius());

    bullet.setModelBound(new BoundingSphere());

    bullet.updateModelBound();

    /** Move bullet to the camera location /

    bullet.setLocalTranslation(new Vector3f(character.getCharacter().getWorldTranslation()));

    bullet.updateGeometricState(0, true);

    bullet.setSolidColor(new ColorRGBA(0,0,0,0));

    bullet.updateRenderState();



    bullet.setRenderQueueMode(Renderer.QUEUE_OPAQUE);

    rootNode.attachChild(bullet);



    ParticleMesh manager = ParticleFactory.buildParticles(“particles”, 20);

    manager.setEmissionDirection(new Vector3f(0.0f, 1.0f, 0.0f));

    manager.setMaximumAngle(0.2f);

    manager.getParticleController().setSpeed(0.5f);

    manager.setMinimumLifeTime(150.0f);

    manager.setMaximumLifeTime(225.0f);

    manager.setStartSize(0.4f);

    manager.setEndSize(0.1f);

    manager.setStartColor(spell.getRPGspell().getColorStart());

    manager.setEndColor(spell.getRPGspell().getColorEnd());

    manager.getParticleController().setControlFlow(false);

    manager.setInitialVelocity(0.12f);

    manager.setGeometry((Geometry)(bullet));



    manager.warmUp(60);

    manager.setRenderState(ts2);

    manager.setRenderState(as1);

    manager.setLightCombineMode(LightCombineMode.Off);

    manager.setTextureCombineMode(TextureCombineMode.Replace);

    ZBufferState zstate = display.getRenderer().createZBufferState();

    zstate.setEnabled(false);

    manager.setRenderState(zstate);

    rootNode.attachChild(manager);

    bullet.addController(new BulletMover(bullet, manager, new Vector3f(x,y,z)));

    }



    class BulletMover extends Controller {

    private static final long serialVersionUID = 1L;

    /
    * Bullet that’s moving /

    RPGspells s;



    TriMesh bullet;



    /
    * Direciton of bullet /

    Vector3f direction;



    /
    * speed of bullet /

    float speed;



    /
    * Seconds it will last before going away /

    float lifeTime;



    ParticleMesh manager;



    BulletMover(TriMesh bullet, ParticleMesh manager, Vector3f direction) {

    this.s = spell.getRPGspell();

    this.bullet = bullet;

    this.manager=manager;

    this.direction = direction;

    this.direction.normalizeLocal();

    this.speed = this.s.getSpeed();

    this.lifeTime = this.s.getLifeTime();

    }



    public void update(float time) {

    lifeTime -= time;

    /
    * If life is gone, remove it /

    if (lifeTime < 0) {

    rootNode.detachChild(bullet);

    rootNode.detachChild(manager);

    bullet.removeController(this);

    return;

    }

    /
    * Move bullet /

    Vector3f bulletPos = bullet.getLocalTranslation();

    bulletPos.addLocal(direction.mult(time * speed));

    bullet.setLocalTranslation(bulletPos);

    /
    * Does the bullet intersect with target? /

    Iterator itr = collisionWalls.iterator();

    while (itr.hasNext()) {

    if (bullet.getWorldBound().intersects(itr.next().getWorldBound())) {

    lifeTime = 0;

    break;

    }

    }

    Iterator monsterItr = monsters.iterator();

    RPGmonster tmp;

    while (monsterItr.hasNext()) {

    tmp=monsterItr.next();

    if (bullet.getWorldBound().intersects(tmp.getMonster().getBody().getWorldBound())) {

    logger.info(tmp.getHp()+ "hp down to “);

    System.out.println(“hit “+tmp.getMonster().getName() + " with “+this.s.getName() + " for " + this.s.getDamage()+” damage”);

    if (!tmp.setHp(tmp.getHp()-this.s.getDamage())) {

    monsters.remove(tmp);

    rootNode.detachChild(tmp.getBody());

    spell = new RPGspells(“Iceblast”,10,40,2,7, new ColorRGBA(0.0f, 0.1f, 1.0f, 0.5f),new ColorRGBA(0.8f, 0.8f, 1.0f, 0.5f));//spell update

    character.gainExperience(120);

    }

    logger.info(””+tmp.getHp());

    lifeTime = 0;

    break;

    }

    }

    }

    }





    class MonsterBulletMover extends Controller {

    private static final long serialVersionUID = 1L;

    /
    * Bullet that’s moving /

    TriMesh bullet;



    /
    * Direciton of bullet /

    Vector3f direction;



    /
    * speed of bullet /

    float speed = 40;



    /
    * Seconds it will last before going away /

    float lifeTime = 5;



    MonsterBulletMover(TriMesh bullet, Vector3f direction) {

    this.bullet = bullet;

    this.direction = direction;

    this.direction.normalizeLocal();

    }



    public void update(float time) {

    lifeTime -= time;

    /
    * If life is gone, remove it /

    if (lifeTime < 0) {

    rootNode.detachChild(bullet);

    bullet.removeController(this);

    return;

    }

    /
    * Move bullet /

    Vector3f bulletPos = bullet.getLocalTranslation();

    bulletPos.addLocal(direction.mult(time * speed));

    bullet.setLocalTranslation(bulletPos);

    /
    * Does the bullet intersect with target? /

    Iterator itr = collisionWalls.iterator();

    while (itr.hasNext()) {

    if (bullet.getWorldBound().intersects(itr.next().getWorldBound())) {

    lifeTime = 0;

    break;

    }

    }

    RPGcharacter tmp = character.getRPGchar();

    if (bullet.getWorldBound().intersects(tmp.getRPGchar().getCharacter().getWorldBound())) {

    logger.info(tmp.getHp()+ "hp down to “);

    System.out.println(“hit “+tmp.getRPGchar().getCharacter().getName() + " with zombie bolt for 10 damage”);

    if (!tmp.setHp(tmp.getHp()-10)) {

    System.out.println(“you are dead”);

    }

    logger.info(””+tmp.getHp());

    lifeTime = 0;

    }

    }

    }

    private void setMovePath() {

    Vector2f mousePosition = new Vector2f(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());

    Ray ray = DisplaySystem.getDisplaySystem().getPickRay(mousePosition, false, new Ray());

    PickResults results = new TrianglePickResults();

    results.setCheckDistance(true);

    rootNode.findPick(ray, results);

    float distance = 0;

    for (int i = 0; i < results.getNumber(); i++) {

    PickData hit = results.getPickData(i);

    if (hit.getTargetMesh().getName().equalsIgnoreCase(“floor”)) {

    distance = hit.getDistance()+1;

    break;

    }

    }

    float calcZ = (float) Math.sqrt(distance
    distance - ray.getOrigin().y
    ray.getOrigin().y);

    float amT,amX,amZ,mX=1,mZ=1;



    amT=Math.abs(ray.getDirection().x)+Math.abs(ray.getDirection().z);

    amX=Math.abs(ray.getDirection().x)/amT;

    amZ=Math.abs(ray.getDirection().z)/amT;



    if (ray.getDirection().z<0) {mZ=-1;}

    if (ray.getDirection().x<0) {mX=-1;}



    float calcT = (float) Math.sqrt(amXamX + amZamZ);

    amT=calcZ/calcT;

    amX=amXamTmX;

    amZ=amZamTmZ;



    walkTo.setLocalTranslation(cam.getLocation().x+(amX), 0, cam.getLocation().z+(amZ));

    }



    public void gotToDestination(Vector3f destination) {

    Vector3f[] way = new Vector3f[2];

    way[0] = character.getCharacter().getLocalTranslation();

    way[1] = destination;

    float distance = way[0].distance(way[1]);

    PolylineCurve curve = new PolylineCurve(“path”, way);

    curve.setSteps(Math.round(distance));



    cc = new CurveController(curve, character.getCharacter());

    character.getCharacter().addController(cc);

    cc.setRepeatType(Controller.RT_CLAMP);

    cc.setUpVector(Vector3f.UNIT_Y);

    cc.setSpeed(character.getMovementSpeed() / (distance * 1));



    }



    public void genRoom(float x, float z, float w, float h, boolean wall1, boolean wall2, boolean wall3, boolean wall4) {

    if (wall1) {

    genWall(x+(w/4)+(hall/4),z+(h/2),b+(w/4)-(hall/4),b);

    genWall(x-(w/4)-(hall/4),z+(h/2),b+(w/4)-(hall/4),b);

    } else {

    genWall(x,z+(h/2),b+(w/2),b);

    }

    if (wall2) {

    genWall(x+(w/2),z+(h/4)+(hall/4),b,b+(h/4)-(hall/4));

    genWall(x+(w/2),z-(h/4)-(hall/4),b,b+(h/4)-(hall/4));

    } else {

    genWall(x+(w/2),z,b,b+(h/2));

    }

    if (wall3) {

    genWall(x+(w/4)+(hall/4),z-(h/2),b+(w/4)-(hall/4),b);

    genWall(x-(w/4)-(hall/4),z-(h/2),b+(w/4)-(hall/4),b);

    } else {

    genWall(x,z-(h/2),b+(w/2),b);

    }

    if (wall4) {

    genWall(x-(w/2),z+(h/4)+(hall/4),b,b+(h/4)-(hall/4));

    genWall(x-(w/2),z-(h/4)-(hall/4),b,b+(h/4)-(hall/4));

    } else {

    genWall(x-(w/2),z,b,b+(h/2));

    }

    genFloor(x,z,w/2,h/2);

    }

    public void genHall(float x1, float z1, float w1, float h1,

    float x2, float z2, float w2, float h2) {

    float w=b;

    float h=b;

    float hp;

    if (x1==x2) {

    if (z1>z2) {

    h=((z1-(h1/2)-b)-(z2+(h2/2)+b))/2;

    hp=z2+(h2/2)+b/2+h;

    } else {

    h=((z2-(h2/2)-b)-(z1+(h1/2)+b))/2;

    hp=z1+(h1/2)+b/2+h;

    }

    genWall(x1+(hall/2),hp+(w/2),w,b+h);

    genWall(x1-(hall/2),hp+(w/2),w,b+h);

    genFloor(x1,hp+(w/2),hall/2,h+b);

    } else {

    if (x1>x2) {

    w=((x1-(w1/2)-b)-(x2+(w2/2)+b))/2;

    hp=x2+(w2/2)+b/2+w;

    } else {

    w=((x2-(w2/2)-b)-(x1+(w1/2)+b))/2;

    hp=x1+(w1/2)+b/2+w;

    }

    genWall(hp+(h/2),z1+(hall/2),b+w,h);

    genWall(hp+(h/2),z1-(hall/2),b+w,h);

    genFloor(hp+(h/2),z1,w+b,hall/2);

    }

    }

    public void genWall(float x, float z, float w, float h) {

    Box collisionWall = new Box(“CollisionBoxH”, new Vector3f(), w, 10, h);

    if (h==b) {

    collisionWall.setName(“CollisionBoxW”);

    }

    collisionWall.setModelBound(new BoundingBox());

    collisionWall.updateModelBound();

    collisionWall.getLocalTranslation().x = x;

    collisionWall.getLocalTranslation().z = z;

    collisionWall.setRenderState(ts2);

    collisionWall.scaleTextureCoordinates(1, 1);

    rootNode.attachChild(collisionWall);

    collisionWalls.add(collisionWall);

    }

    public void genFloor(float x, float z, float w, float h) {

    Box floor = new Box(“Floor”, new Vector3f(), w, 1, h);

    floor.setModelBound(new BoundingBox());

    floor.updateModelBound();

    floor.getLocalTranslation().x = x;

    floor.getLocalTranslation().z = z;

    floor.setRenderState(ts);

    floor.scaleTextureCoordinates(1, 1);

    rootNode.attachChild(floor);

    }

    @Override

    protected void simpleUpdate() {

    int collisionSide=0;

    int collisionSide2=0;

    boolean wlk=false;

    Iterator itr = collisionWalls.iterator();

    Box tmp;

    while (itr.hasNext()) {

    tmp=itr.next();

    if (character.getCharacter().getWorldBound().intersects(tmp.getWorldBound())) {

    if (collisionSide > 0) {

    collisionSide2=collisionSide;

    }

    if (tmp.getName().equalsIgnoreCase(“CollisionBoxH”)) {

    collisionSide=4;

    if (tmp.getLocalTranslation().x>character.getCharacter().getLocalTranslation().x) {

    collisionSide=2;

    }

    } else {

    collisionSide=1;

    if (tmp.getLocalTranslation().z>character.getCharacter().getLocalTranslation().z) {

    collisionSide=3;

    }

    }

    }

    if (collisionSide2>0) {

    break;

    }

    }

    if (MouseInput.get().isButtonDown(0) && !leftDown) {

    mousePick();

    leftDown=!leftDown;

    }

    if (MouseInput.get().isButtonDown(0) && moveChar) {

    setMovePath();

    wlk=true;

    }

    if (!MouseInput.get().isButtonDown(0) && leftDown) {

    leftDown=!leftDown;

    moveChar=false;

    }

    monsterCheck();

    if (wlk) {

    float x,y,z;

    y=5;

    x=walkTo.getLocalTranslation().x;

    z=walkTo.getLocalTranslation().z;

    if (collisionSide==0) {

    gotToDestination(walkTo.getLocalTranslation());

    }

    if (collisionSide==1 || collisionSide2==1){

    z=character.getCharacter().getLocalTranslation().z+1f;

    }

    if (collisionSide==2 || collisionSide2==2){

    x=character.getCharacter().getLocalTranslation().x-1f;

    }

    if (collisionSide=:3 || collisionSide2=:3){

    z=character.getCharacter().getLocalTranslation().z-1f;

    }

    if (collisionSide==4 || collisionSide2==4){

    x=character.getCharacter().getLocalTranslation().x+1f;

    }

    gotToDestination(new Vector3f(x,y,z));

    }

    cam.setLocation(new Vector3f(character.getCharacter().getWorldTranslation().x, 300, character.getCharacter().getWorldTranslation().z+1));

    cam.lookAt(character.getCharacter().getLocalTranslation(), camDirUp);

    }

    public void monsterCheck() {

    Iterator monsterItr = monsters.iterator();

    RPGmonster tmp;

    while (monsterItr.hasNext()) {

    tmp=monsterItr.next();

    tmp.getMonster().getBody().lookAt(new Vector3f(character.getRPGchar().getCharacter().getLocalTranslation()).subtract(tmp.getMonster().getBody().getLocalTranslation()), camDirUp);

    if (new Vector3f(character.getRPGchar().getCharacter().getLocalTranslation()).distance(tmp.getMonster().getBody().getLocalTranslation()) < tmp.getMonster().getRange()) {

    if (tmp.getMonster().getNextShot() < time.getMsTime()) {

    Sphere bullet = new Sphere(“monsterBullet”, 8, 8, 2f);

    bullet.setModelBound(new BoundingSphere());

    bullet.updateModelBound();

    /** Move bullet to the camera location */

    bullet.setLocalTranslation(new Vector3f(tmp.getMonster().getBody().getLocalTranslation()));

    bullet.updateGeometricState(0, true);

    bullet.addController(new MonsterBulletMover(bullet, new Vector3f(character.getRPGchar().getCharacter().getLocalTranslation()).subtractLocal(tmp.getMonster().getBody().getLocalTranslation())));

    bullet.setDefaultColor(ColorRGBA.gray);

    rootNode.attachChild(bullet);

    bullet.updateRenderState();

    tmp.getMonster().setLastShot(time.getMsTime());

    }

    }

    }

    }



    /**
  • Black opengl render magic needed for nifty integration (lots of guessing in here)

    */

    @Override

    protected void simpleRender() {

    GL11.glPushAttrib(GL11.GL_LIGHTING_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_CURRENT_BIT | GL11.GL_TEXTURE_BIT | GL11.GL_TRANSFORM_BIT | GL11.GL_VIEWPORT_BIT);

    GL11.glMatrixMode(GL11.GL_PROJECTION);

    GL11.glPushMatrix();

    GL11.glLoadIdentity();

    GL11.glOrtho(0, viewportWidth, viewportHeight, 0, -9999, 9999);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glPushMatrix();

    GL11.glLoadIdentity();

    GL11.glDisable(GL11.GL_DEPTH_TEST);

    GL11.glEnable(GL11.GL_BLEND);

    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glEnable(GL11.GL_ALPHA_TEST);

    GL11.glAlphaFunc(GL11.GL_NOTEQUAL, 0);

    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glDisable(GL11.GL_TEXTURE_2D);

    GL13.glActiveTexture(GL13.GL_TEXTURE0);

    nifty.render(false);

    int error = GL11.glGetError();

    if (error != GL11.GL_NO_ERROR) {

    String glerrmsg = GLU.gluErrorString(error);

    logger.warning(“OpenGL Error: (” + error + ") " + glerrmsg);

    }

    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glPopMatrix();

    GL11.glMatrixMode(GL11.GL_PROJECTION);

    GL11.glPopMatrix();

    GL11.glPopAttrib();

    }



    private void setupWalls() {

    genRoom(0,0,100,100,true,true,true,true);

    genRoom(0,140,100,100,false,false,true,false);

    genHall(0,0,100,100,0,140,100,100);

    genRoom(190,0,200,200,false,true,false,true);

    genHall(0,0,100,100,190,0,200,200);

    genRoom(380,0,100,100,false,false,false,true);

    genHall(190,0,200,200,380,0,100,100);

    genRoom(0,-190,100,200,true,false,false,false);

    genHall(0,0,100,100,0,-190,100,200);

    genRoom(-140,0,100,100,false,true,false,false);

    genHall(0,0,100,100,-140,0,100,100);

    genMonster(“Skeleton”, -20,-140,100,100,20);

    genMonster(“Zombie”, 20,140,100,100,100);

    }

    private void genMonster(String name, float x, float z, float hp, float mana, float range) {

    RPGmonster monster = new RPGmonster(name,x,z,hp,mana,range);

    rootNode.attachChild(monster.getBody());

    monsters.add(monster);

    }



    private static boolean initInput() {

    try {

    inputSystem = new LwjglInputSystem();

    inputSystem.startup();

    return true;

    } catch (Exception e) {

    e.printStackTrace();

    logger.info(“Unable to create keyboard!, exiting…”);

    return false;

    }

    }

    public void initSpell() {

    spell = new RPGspells(“Fireball”,10,40,2,7,new ColorRGBA(1.0f, 0.112f, 0.121f, 0.5f),new ColorRGBA(1.0f, 0.632f, 0.131f, 0.5f));

    }

    public void setupTexturesAndFloors() {

    Box floor = new Box(“Floor”, new Vector3f(), 500, 0, 500);



    floor.setModelBound(new BoundingBox());

    floor.updateModelBound();

    ts = display.getRenderer().createTextureState();

    t0 = TextureManager.loadTexture(

    RPG_low.class.getClassLoader().getResource(“data/bgtexture.jpg”),

    Texture.MinificationFilter.Trilinear,

    Texture.MagnificationFilter.Bilinear);

    t0.setWrap(Texture.WrapMode.EdgeClamp);

    ts.setTexture(t0);

    floor.setRenderState(ts);

    floor.scaleTextureCoordinates(1, 1);

    rootNode.attachChild(floor);



    ts = display.getRenderer().createTextureState();

    t0 = TextureManager.loadTexture(

    RPG_low.class.getClassLoader().getResource(“data/floor.jpg”),

    Texture.MinificationFilter.Trilinear,

    Texture.MagnificationFilter.Bilinear);

    t0.setWrap(Texture.WrapMode.Repeat);

    ts.setTexture(t0);



    ts2 = display.getRenderer().createTextureState();

    t2 = TextureManager.loadTexture(

    RPG_low.class.getClassLoader().getResource(“data/wall.jpg”),

    Texture.MinificationFilter.Trilinear,

    Texture.MagnificationFilter.Bilinear);

    t2.setWrap(Texture.WrapMode.Repeat);

    ts2.setTexture(t2);



    t4 = TextureManager.loadTexture(

    RPG_low.class.getClassLoader().getResource(“data/flaresmall.jpg”),

    Texture.MinificationFilter.Trilinear,

    Texture.MagnificationFilter.Bilinear);



    as1 = display.getRenderer().createBlendState();

    as1.setBlendEnabled(true);

    as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha);

    as1.setDestinationFunction(BlendState.DestinationFunction.One);

    as1.setTestEnabled(true);

    as1.setTestFunction(BlendState.TestFunction.GreaterThan);

    as1.setEnabled(true);



    ts4 = display.getRenderer().createTextureState();

    ts4.setTexture(t4);

    ts4.setEnabled(true);



    rootNode.setLightCombineMode(LightCombineMode.Off);

    }

    }[/java]





    where i would guess the important stuff according to my problem with nifty not being intractable lies within

    [java] JmeNiftyInputSystem jmeNiftyinput = new JmeNiftyInputSystem();

    MouseInput.get().addListener(jmeNiftyinput);

    KeyInput.get().addListener(jmeNiftyinput);

    jmeNiftyinput.bind(nifty);



    nifty = new Nifty(new RenderDeviceLwjgl(),

    new SoundSystem(new SlickSoundDevice()),

    jmeNiftyinput,

    new TimeProvider());

    nifty.fromXml(“data/rpg.xml”, “start”);[/java]



    anyways, thanks for for taking the time to help me figure this out

    -Magnus

What version of the Nifty JME2 Renderer do you use? I think the current SVN Version looks a bit different.



I’m a bit confused now because you seem to mix Jme Renderer Nifty classes with the native Lwjgl Nifty Renderer classes :slight_smile:



A JME2 specific setup tutorial was added to the Nifty wiki at sf.net recently by some other Nifty user. You can find it here: https://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Using_Nifty_with_JMonkeyEngine_2. Can you get it to work following that tutorial?



Thanks for posting your code! It is a bit much to understand tho :slight_smile:



If the turorial above does not help you, can you zip the whole project and make it available somehow?

Thank you again void, I will try this the second I have the time, guessing monday morning.

I will then give a writeup on what i did and how the results went, for people who might have the same problem.