Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Slick2D, Nifty GUI interaction problem

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 PredaNoob   Members   -  Reputation: 100


Posted 01 February 2012 - 08:43 AM

Hello all!

I'm trying to get Nifty to work with Slick2D. So far everything is going great, except that I can't seem to figure out how to properly interact with the GUI. I'm trying the example in the nifty manual http://sourceforge.n....0.pdf/download
but it doesn't seem to entirely work. The Element controller is being called for bind(...), init(...) and onStartScreen() as it should, as I can see their println output, but the next() method isn't being called when I click on the GUI element that I assigned the controller to, nor the screen controller as no println is shown.
It's supposed to be called when I click the mouse button on it from the <interact onClick="next()" /> in the XML.

Here is my code:

My Element controller:
public class ElementController implements Controller {

private Element element;

public void bind(Nifty nifty, Screen screen, Element element, Properties parameter, Attributes controlDefinitionAttributes) {
  this.element = element;
  System.out.println("bind() called for element: " + element);

public void init(Properties parameter, Attributes controlDefinitionAttributes) {
  System.out.println("init()  called for element: " + element);

public void onStartScreen() {
  System.out.println("onStartScreen()  alled for element: " + element);

public void onFocus(boolean getFocus) {
  System.out.println("onFocus()  called for element: " + element + ", with: " +

public boolean inputEvent(NiftyInputEvent inputEvent) {
  return false;

public void next() {
  System.out.println("next() clicked for element: " + element);

class MyScreenController implements ScreenController {
	public void bind(Nifty nifty, Screen screen) {}
	public void onEndScreen() {}
	public void onStartScreen() {}
	public void next() {
	 System.out.println("next() called from MyScreenController");

And my 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://niftygui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<screen id="start" controller="predaN00b.theThing.V0004.MyScreenController">
  <layer childLayout="center" controller="predaN00b.theThing.V0004.ElementController">
   <panel width="100px" height="100px" childLayout="vertical" backgroundColor="#ff0f">
	 <text font="aurulent-sans-16.fnt" color="#ffff" text="Hello World!">
	  <interact onClick="next()" />

My main class, in case it's needed:
My main class:
public class MainGameState extends BasicGame {

public Nifty nifty;

public MainGame() {

public void init(GameContainer container, StateBasedGame game) throws SlickException {

  nifty = new Nifty(new SlickRenderDevice(container), new NullSoundDevice(), new PlainSlickInputSystem(), new AccurateTimeProvider());



public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {

public void render(GameContainer container, StateBasedGame game, Graphics graphics) throws SlickException {
  public static void main(String[] args) throws SlickException {
	 AppGameContainer app = new AppGameContainer(new MainGame());
	 app.setDisplayMode( 1260 , 720, false); //window size


#2 PredaNoob   Members   -  Reputation: 100


Posted 04 February 2012 - 04:47 PM

Bumpy bump.

It's weird.. I'm using the PlainSlickInputSystem, which should not only let Nifty get the input events, but also prevent any from going to my game, which after putting a listener, I discovered was still getting the inputs instead of Nifty..

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.