gpt4 book ai didi

java - jMonkeyEngine 忽略 Nifty GUI 形式的键盘输入

转载 作者:行者123 更新时间:2023-11-30 06:03:41 27 4
gpt4 key购买 nike

使用 Nifty GUI 创建游戏登录表单。该界面对鼠标的移动和单击使用react,但忽略文本字段中的输入。程序是否正在寻找点击处理程序,而不是打字,或者我不知道是什么。可能是什么情况以及如何解决?

界面/screen.xml:

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd
https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
<useStyles filename="nifty-default-styles.xml"/>
<useControls filename="nifty-default-controls.xml"/>
<screen id="start" controller="mygame.LoginScreen">
<layer id="background" childLayout="center">
<image filename="Interface/start-background.jpg"></image>
</layer>
<layer id="foreground" childLayout="center">
<panel id="panel" height="25%" width="75%" align="center" childLayout="horizontal">
<panel id="panel_left" height="100%" width="25%" align="left" childLayout="vertical">
<text text="E-mail:" font="Interface/Fonts/Default.fnt"/>
<text text="Password:" font="Interface/Fonts/Default.fnt"/>
</panel>
<panel id="panel_center" height="100%" width="50%" align="center" childLayout="vertical">
<control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>
</panel>
<panel id="panel_right" height="100%" width="25%" align="right" childLayout="vertical">

</panel>
</panel>
</layer>
</screen>
<screen id="hud" controller="de.lessvoid.nifty.screen.DefaultScreenController">

</screen>
</nifty>

src/mygame/Main.java:

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;

public class Main extends SimpleApplication {

public static void main(String[] args) {
Main app = new Main();
app.start();
}
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
public Nifty nifty = null;
@Override
public void simpleInitApp() {
NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml("Interface/screen.xml", "start");
guiViewPort.addProcessor(niftyDisplay);
inputManager.beginInput();
flyCam.setDragToRotate(true);
}

@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
nifty.update();
inputManager.update(tpf);
}
}

src/mygame/LoginScreen.java:

package mygame;

import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

public class LoginScreen extends BaseAppState implements ScreenController {

@Override
protected void initialize(Application app) {

}

@Override
protected void cleanup(Application app) {

}

@Override
protected void onEnable() {

}

@Override
protected void onDisable() {

}
@Override
public void update(float tpf) {

}

@Override
public void bind(Nifty nifty, Screen screen) {

}

@Override
public void onStartScreen() {

}

@Override
public void onEndScreen() {

}
}

最佳答案

错误出现在 XML 中。没有 id 的交互界面元素保持静态。不必如此:

<control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>

好吧:

<control id="mail" name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control id="password" name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>

然后字段被激活。

关于java - jMonkeyEngine 忽略 Nifty GUI 形式的键盘输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51777397/

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