2016-12-27 50 views
0

我做我自己的關卡編輯器,我想當按下空格鍵將光標變爲手:爲什麼setSystemCursor()不工作(libgdx)?

@Override 
public boolean keyDown(InputEvent event, int keycode) { 
    switch (keycode) { 
    case Input.Keys.SPACE: 
     System.out.println("Spacebar is pressed"); 
     Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Hand); 
     break; 
    } 
    return true; 
} 

@Override 
public boolean keyUp(InputEvent event, int keycode) { 
    switch (keycode) { 
    case Input.Keys.SPACE: 
     Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow); 
     break; 
    } 
    return true; 
} 

但它不工作,我不知道爲什麼...什麼我做錯了?

+0

當你說「它不工作」,你是什麼意思?你有錯誤嗎? keyDown沒有被呼叫?它沒有檢測到空格鍵嗎? – John

+0

按空格鍵時,它會打印'空格鍵被按下',但光標不會改變,並且我不會收到任何錯誤。 – Lordeblader

回答

1

根據Libgdx wiki page它需要LWJGL3後端:

您還可以更改光標移動到系統光標,在 LWJGL3後端並在後端GWT僅工作。這是可以做到如下:

Gdx.graphics.setSystemCursor(SystemCursor.Crosshair); 

以下是從原來的issue採取:

您可以輕鬆地切換出LWJGL 2後端在搖籃中LWJGL 3後端 。在你的核心項目的依賴,改變:

compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" 

compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion" 

確保gdxVersion設置爲最新的快照版本1.7.3快照。 在你的桌面快速啓動,只需用Lwjgl3ApplicationConfiguration取代LwjglApplicationConfiguration 和LwjglApplication和 Lwjgl3Application

+0

非常感謝! – Lordeblader