【问题标题】:Nifty Gui doesn't react to inputNifty Gui 对输入没有反应
【发布时间】:2017-01-30 18:54:50
【问题描述】:

早上好! 我正在用 Slick2d 尝试 Nifty Gui。除了 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();

我没有想法,为什么没有。请帮忙!谢谢!

【问题讨论】:

    标签: java xml user-interface slick2d nifty-gui


    【解决方案1】:

    这应该适合你:

        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 集成。

    【讨论】:

      【解决方案2】:

      你有没有在 LwjglInputSystem 上调用过startup() 方法?我们有可用的示例代码here 说明如何调用它。这是正确初始化 LwjglInputSystem 所必需的。

      但是,您为什么不使用我们在此处提供的现成的 Slick2d 集成类:Slick2d Nifty-GUI classes?它们可能更适合轻松地将 Nifty GUI 与 Slick2d 集成,而不是直接依赖 LWJGL。

      【讨论】:

      • 谢谢,但您的解决方案不起作用。是的,我尝试过 Nifty + Slick 2d 状态,但它们没有帮助我。谢谢你的回答!
      猜你喜欢
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 2015-10-20
      • 2021-11-09
      • 2016-10-11
      相关资源
      最近更新 更多