我在InputProcessor的touchDown方法中遇到了枚举问题。当我尝试使用它时,它会生成所有可能的枚举...
public class Memoration implements ApplicationListener, InputProcessor {
public static enum Screen {GAME, MENU}
Screen screen;
@Override
public void create() {
screen = Screen.MENU;
Gdx.app.log("onCreate", "works");
Gdx.input.setInputProcessor(this);
}
@Override
public void dispose() {
}
@Override
public void render() {
// bla bla bla
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Gdx.app.log("touch", "down");
if(screen == null)
Gdx.app.log("screen", "null");
if(screen == Screen.MENU)
Gdx.app.log("screen", "menu");
if(screen == Screen.GAME)
Gdx.app.log("screen", "game");
return false;
}
}
日志显示“onCreate:workds”,“touch:down”,“screen:null”,“screen:menu”和“screen:game”
答案 0 :(得分:3)
您的类名为 Memoration 并实现 InputProcessor 。但是,在 create()回调中,您正在创建 Memoration 的另一个实例并将其设置为输入处理器,因此它就是获取回调的实例。并且,因为没有为该实例调用 create(),所以 screen 永远不会被初始化。
试试这个......
@Override
public void create() {
screen = Screen.MENU;
Gdx.app.log("onCreate", "works");
Gdx.input.setInputProcessor(this);
}