I got a working pong game in LibGDX but when I touch the screen the player x automaticly jumps to the coordinates I touched. I wan't my game to detect I touched and then move the player to the left/right if I swipe my finger to the left or the right.
This is what I tried so far:
if(Gdx.input.isTouched() && Gdx.input.getY()>240*screenheight){
if(tapped)TouchX = Gdx.input.getX();
tapped = false;
DragX = Gdx.input.getX();
distance = player.getX() - TouchX;
PlayerX = Gdx.input.getX() + distance;
Gdx.app.log("PlayerX "+player.getX(), "Distance "+distance);
Gdx.app.log("DragX ", ""+DragX);
}else{
tapped = true;
}
Here I update the player X coordinates
player.setX(PlayerX);
Does anyone know how to make this work?
No comments:
Post a Comment