Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

Multiple input not working properly

$
0
0

I have 3 different buttons, one for each action. I want to be able to jump and walk at the same time, but there’s a little problem. jumpButton doesn’t work while I’m pressing leftButton or rightButton but the opposite works.

I have no idea what I’m doing wrong.

public void handleInput() {
    float x0 = (Gdx.input.getX(0) / (float)Gdx.graphics.getWidth()) * 960;
    float x1 = (Gdx.input.getX(1) / (float)Gdx.graphics.getWidth()) * 960;
    float y0 = (Gdx.input.getY(0) / (float)Gdx.graphics.getHeight()) * 640;
    float y1 = (Gdx.input.getY(1) / (float)Gdx.graphics.getHeight()) * 640;

    boolean jumpButton = (Gdx.input.isTouched(0) && x0 > 850 && x0 < 850+80 && y0 > 640-80);
    boolean leftButton = ( ((Gdx.input.isTouched(0) && x0 < 25+80) || (Gdx.input.isTouched(1) && x1 < 25+80)) && ((Gdx.input.isTouched(0) && x0 > 25) || (Gdx.input.isTouched(1) && x1 > 25)) && ((Gdx.input.isTouched(0) && y0 > 640-80) || (Gdx.input.isTouched(1) && y1 > 640-80)));
    boolean rightButton = ( ((Gdx.input.isTouched(0) && x0 < 125+80) || (Gdx.input.isTouched(1) && x1 < 125+80)) && ((Gdx.input.isTouched(0) && x0 > 125) || (Gdx.input.isTouched(1) && x1 > 125)) && ((Gdx.input.isTouched(0) && y0 > 640-80) || (Gdx.input.isTouched(1) && y1 > 640-80)));

    if (jumpButton) {
        // player jumps
    }
    if (leftButton) {
        // player walks to the left
    } else if (rightButton) {
        // player walks to the right
    } else {
        // player stops walking
    }
}

Viewing all articles
Browse latest Browse all 434

Trending Articles