Wednesday, July 19, 2017

java - Simple LibGDX Pong game drag player instead of getting x position


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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...