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

unable to use two gestures simultaneously

$
0
0

I have a class implementing gesture listener in libgdx. I want to use longpress gesture in one half of the screen and fling gesture in other part of the screen simultaneously.

public class FlingHandler implements GestureDetector.GestureListener{

GameWorld world;
Bmw bmw;
private float  w,h,xunit, yunit;
private float spd = 1;
private float xtouch = 0, ytouch = 0;
private float xVel = 0, yVel = 0;
private int p = 0;


public FlingHandler(GameWorld world) {
    this.world = world;
    w = SS.WIDTH;
    h = SS.HEIGHT;
    xunit = SS.x;
    yunit = SS.y;
    bmw = world.getBmw();

}
public void update(float delta){
    updateLongpress(delta);
}

public void updateLongpress(float delta){

    if(longPress(xtouch,ytouch)==true && world.getBmw().isDead()==false) {
        if(spd <1600 && Gdx.input.isTouched()){
            spd += 0.9f*delta;
            Gdx.app.log("speed ","increasing"+spd);
        }
    }

    else if(longPress(xtouch,ytouch)==false && world.getBmw().isDead()==false){

            if(spd > 1 ){
                spd -= 8f*delta;
                Gdx.app.log("speed ","decreasing"+spd);
            }
    }
    else{

    }
}

@Override
public boolean fling(float velocityX, float velocityY, int button) {
    xVel = velocityX;
    yVel = velocityY;
    xtouch=Gdx.input.getX();
    ytouch=Gdx.input.getY();
    p = button;

    if(xtouch > SS.WIDTH/2 && world.getBmw().isDead()==false) {
        if (Math.abs(xVel) > Math.abs(yVel)) {
            if (xVel > 0) {
                if (world.getBmw().getPosition().x < 8 * xunit) {
                    world.getBmw().getPosition().x += 4 * xunit;
                }
            } else if (xVel < 0) {

                if (world.getBmw().getPosition().x > 7 * xunit) {
                    world.getBmw().getPosition().x -= 4 * xunit;
                }

            } else {}

        }
        return true;
    }
    else
    return false;
}

@Override
public boolean longPress(float x, float y) {
    xtouch = Gdx.input.getX();
    ytouch = Gdx.input.getY();

    if(xtouch < SS.WIDTH/2 && world.getBmw().isDead()==false){
        return true;
    }
    else if (xtouch > SS.WIDTH/2){
        return false;
    }
    else
    return false;
}

Viewing all articles
Browse latest Browse all 434

Trending Articles