0

我在 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”

4

1 回答 1

3

您的课程称为Memoration并实现InputProcessor。但是,在您的create()回调中,您正在创建另一个Memoration实例并将其设置为输入处理器,因此获取回调的是该实例。而且,因为没有为该实例调用create() ,所以screen永远不会初始化。

试试这个...

@Override
public void create() {
   screen = Screen.MENU;
   Gdx.app.log("onCreate", "works");
   Gdx.input.setInputProcessor(this);
}
于 2013-03-08T15:27:33.393 回答