Nifty-GUI의 이벤트 처리에 많은 문제가있어 인터넷에서 솔루션을 검색했지만 실제로 찾지 못했습니다. InputSystem). 문제는 응용 프로그램에서 nifty를 사용하자마자 LWJGL이 더 이상 키보드 입력을받지 못하는 것입니다. 나는 이미 nifty.setIgnoreKeyboardEvents(true)
과 같은 여러 가지를 시도했지만 아무 것도 변경하지 않습니다. 나는 아마 내가 뭔가 잘못하고 있다는 것을 알고 있지만, 누군가 나를 도와 줄 수 있기를 바랍니다. Nifty-GUI 1.4는 키보드 이벤트 (LWJGL 2.9.2)를 사용합니다.
이
는 관련 코드 발췌 :하는 UI 클래스가 멋진 설정에 대한 책임이 있습니다. 이 클래스는 LnJGL과 OpenGL을 초기화 한 후에 만 Graphics (Runnable을 구현하는 중요한 클래스)라는 다른 클래스에서 인스턴스화됩니다.
는public class UI {
private Nifty nifty;
public UI() {
initUI();
}
private void initUI() {
LwjglInputSystem inputSystem = initInput();
nifty = initNifty(inputSystem);
nifty.setIgnoreKeyboardEvents(true);
nifty.fromXml("resources/ClientStartScreen.xml", "start",
new ClientStartController());
}
private LwjglInputSystem initInput() {
try {
LwjglInputSystem inputSystem = new LwjglInputSystem();
inputSystem.startup();
inputSystem.niftyHasKeyboardFocus = false;
inputSystem.niftyTakesKeyboardFocusOnClick = false;
return inputSystem;
} catch(Exception e) {
System.out.println("[ERROR:] Input System could not be"
+ "initialised.");
System.out.println(e.getMessage());
return null;
}
}
private Nifty initNifty(LwjglInputSystem inputSystem) {
try {
return new Nifty(new BatchRenderDevice(
LwjglBatchRenderBackendCoreProfileFactory.create()),
new NullSoundDevice(), inputSystem,
new AccurateTimeProvider());
} catch(Exception e) {
System.out.println("[ERROR:] Nifty could not be initialised.");
System.out.println(e.getMessage());
return null;
}
}
public Nifty getNifty() {
return nifty;
}
}
내가 사용 화면은 최소한의 예, 그래서 여기 저기 아무 문제가 없어야합니다 :
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="start"
controller="htw.gt3.trappers.client.screens.ClientStartController">
<layer childLayout="center">
<text id="hellouser" font="aurulent-sans-16.fnt" color="#ffff"
text="Hello user!" />
</layer>
</screen>
</nifty>
그리고 컨트롤러는 빈 덮어 쓰기 방법이 있습니다, 아무것도하지 않습니다.
입력을 처리하는 별도의 클래스를 사용하고 있습니다. 이것은 게임의 메인 루프 (Graphics 클래스의 일부)의 일부입니다. 내가 말했듯이 그들은 아마도 전에 멋진 의해 소비하고 같은 키보드 이벤트를 수신하지 않기 때문에
가public void checkInput() {
while(Keyboard.next()) {
if(!Keyboard.getEventKeyState()) {
if(Keyboard.getEventKey() == Keyboard.KEY_UP) {
그러나 게임이 while 루프를 입력하지 : 다음과 같이 루프라고 관련 방법은 시작 . nifty를 사용하지 않을 때는 제 코드가 제대로 작동합니다. 따라서 Graphics 클래스에서 UI 객체를 생성하지 않고 아무 것도 사용하지 않고 그냥 검은 색 화면을 유지하면 입력이 정상적으로 작동합니다.
메인 루프는 다음과 같습니다
boolean niftyDone = false;
while(!Display.isCloseRequested() && !niftyDone) {
controls.checkInput();
Display.update();
Display.sync(60);
if(ui.getNifty().update()) {
niftyDone = true;
}
ui.getNifty().render(true);
}
정말 여기 당신의 도움에 의존이 - 희망 누군가가 문제가 될 수있는 것을 알고있다.