Created
April 30, 2020 03:47
-
-
Save mgsx-dev/059ecae615c14f7095588e6b632486bc to your computer and use it in GitHub Desktop.
Libgdx keyboard abstract controls for ARROWS, WSAD, ZSQD layouts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.Input; | |
public class UniControl { | |
public static final int DOWN = 1, RIGHT = 3, UP = 0, LEFT = 2; | |
// Layouts ARROWS, WSAD, ZSQD | |
private static final int [][] keyLayouts = { | |
{Input.Keys.UP, Input.Keys.DOWN, Input.Keys.LEFT, Input.Keys.RIGHT}, | |
{Input.Keys.W, Input.Keys.S, Input.Keys.A, Input.Keys.D}, | |
{Input.Keys.Z, Input.Keys.S, Input.Keys.Q, Input.Keys.D}, // this one is not necessary with LWJGL3 backend. | |
}; | |
public static boolean isPressed(int direction){ | |
for(int [] keyLayout : keyLayouts){ | |
if(Gdx.input.isKeyPressed(keyLayout[direction])) return true; | |
} | |
return false; | |
} | |
public static boolean isJustPressed(int direction){ | |
for(int [] keyLayout : keyLayouts){ | |
if(Gdx.input.isKeyJustPressed(keyLayout[direction])) return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment