早上好!我正在和Slick2d一起尝试漂亮的图形用户界面。除了Nifty Gui的输入轮询之外,一切都正常工作。它一点反应都没有!下面是我的代码的一部分:
Xml:
<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
<screen id="GamePlay" controller="GamePlayScreenController">
<layer childLayout="vertical">
<panel id="roomListPanel" width="100%" height="32px"
childLayout="absolute-inside" padding="5px">
<control id="appendButton" name="button" label="Pause">
<interact onClick="test()" />
</control>
</panel>
</layer>
</screen>
</nifty>Java:
class GamePlayScreenController implements ScreenController {
public void bind(Nifty nifty, Screen screen) {
System.out.println("Bind");
}
public void onEndScreen() {
System.out.println("End");
}
public void onStartScreen() {
System.out.println("Start");
}
public void test() {
System.out.println("Test");
}
}
...
// In my state class:
this.nifty = new Nifty(new LwjglRenderDevice(), new NullSoundDevice(), new LwjglInputSystem(), new TimeProvider());
this.nifty.loadStyleFile("nifty-default-styles.xml");
this.nifty.loadControlFile("nifty-default-controls.xml");
this.nifty.registerScreenController(new GamePlayScreenController());
this.nifty.fromXml("data/test.xml", "GamePlay");
this.nifty.gotoScreen("GamePlay");
...
this.nifty.update();
...
SlickCallable.enterSafeBlock();
this.nifty.render(false);
SlickCallable.leaveSafeBlock();我不知道,为什么它不是。求求你,救命!谢谢!
发布于 2016-10-24 15:27:48
这对你来说应该是可行的:
protected void initGameAndGUI(GameContainer arg0, StateBasedGame arg1) {
LwjglInputSystem inputSystem = new LwjglInputSystem();
try {
inputSystem.startup();
} catch (Exception e) {
e.printStackTrace();
}
PlainSlickInputSystem psis = new PlainSlickInputSystem();
GameClient.app.getInput().addListener(psis);
prepareNifty(nifty, arg1);
nifty = new Nifty(new LwjglRenderDevice(), new NullSoundDevice(),psis, new AccurateTimeProvider());
NullSoundDevice(),psis, new AccurateTimeProvider());
initNifty(arg0, arg1, psis);
nifty.fromXml("...");
}当然还有
nifty.update();在你的update方法中。
我使用的是Slick2d漂亮的集成。
发布于 2016-09-25 21:06:02
那么你在LwjglInputSystem上调用startup()方法了吗?关于如何调用它,我们有可用的示例代码here。这是正确初始化LwjglInputSystem所必需的。
但是,您为什么不使用我们这里提供的现成的Slick2d集成类:Slick2d Nifty-GUI classes?它们可能更适合于轻松地将Nifty GUI与Slick2d集成,而不是直接依赖LWJGL。
https://stackoverflow.com/questions/39634918
复制相似问题