2013-03-08 75 views
0

我在InputProcessor的touchDown方法中遇到了一些問題。當我嘗試用它生成所有可能的枚舉...在TouchEvent中枚舉行爲奇怪

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」,「摸:下」,「畫面:空」,「屏幕:菜單」和「screen:game」

+0

似乎代碼是不完整。你可以發佈整個活動嗎? – Gyonder 2013-03-08 14:59:32

+0

即使我刪除了我的所有代碼,只有上面的代碼纔會發生! – Daniel 2013-03-08 15:06:19

回答

3

您的課程名爲記憶和實施InputProcessor。但是,在您的create()回調中,您正在創建另一個回憶實例並將其設置爲輸入處理器,因此它就是獲取回調的實例。並且,因爲create()沒有被調用,所以屏幕從不初始化。

試試這個...

@Override 
public void create() { 
    screen = Screen.MENU; 
    Gdx.app.log("onCreate", "works"); 
    Gdx.input.setInputProcessor(this); 
} 
+0

謝謝你的回答棒!欣賞它,但不幸的是它現在不工作,同樣的結果! – Daniel 2013-03-08 15:32:00

+0

奇數。適用於我。這是我使用的代碼(應該獨立工作)。 http://pastebin.com/mAyg2qFY – 2013-03-08 15:33:52

+0

是的,它也適用於我! (除了導入com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;) 我將檢查我在做什麼我的代碼錯了! 謝謝你的幫助。 – Daniel 2013-03-08 15:38:15