【发布时间】:2020-06-07 14:07:57
【问题描述】:
这是来自 LibGDX 框架,我正在调用方法
Gdx.input.isKeyPressed(Input.Keys.LEFT);
这是 Gdx 类的相关部分:
public class Gdx {
//..
public static Input input;
//..
}
以及Input的相关部分:
public interface Input {
//..
public class Keys { //..
}
//..
public boolean isKeyPressed (int key);
//..
}
最糟糕的是它的工作!如果我按下左箭头,则返回 true。
我不明白为什么,看起来好像我在调用一个没有实现的接口方法。
我将留下两个类的源代码链接:
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/Gdx.java
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/Input.java
【问题讨论】:
-
它在库的其他地方通过具体代码(可能是本机代码)实现,并分配给静态字段。
-
每个后端都有一个实现这个接口的类。例如,有LwjglInput 和AndroidInput。如果您使用调试器并检查
Gdx.input的值是什么类型,您就会知道正在使用什么类。
标签: java methods interface libgdx