Search code examples
javaandroidlibgdx

LibGdx 2 half screen "buttons"


(Android) So I'm new to LibGdx and I'm trying to code this chrome dino mini game.. I want to make action 1 when the user touch the left hand side of the screen and make action 2 when he touch the right hand side of the screen, how can I do it?


Solution

  • You can detect the side being touched by using the following code somewhere inside your game loop:

    if (Gdx.input.isTouched()) {
        if (Gdx.input.getX() > Gdx.graphics.getWidth() / 2){
            //touched right
        } else {
            //touchde left
        }
    }