gpt4 book ai didi

java - Nifty Gui 对输入没有反应

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:37 26 4
gpt4 key购买 nike

早上好!我正在尝试使用 Nifty Gui 和 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();

我不知道为什么不行。请帮忙!谢谢!

最佳答案

这应该适合你:

    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();

在您的更新方法中。

我正在使用 Slick2d Nifty 集成。

关于java - Nifty Gui 对输入没有反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39634918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com