I want to create a mobile application which allows two players to play pong on the same device. Each player will grab an end of the device and be able to move their goalie back and forth on the y-axis. I'm developing the game using Java w/ LibGDX, and I'm having trouble getting multiple input to work. I can make it so that the platform registers that input is coming in on either the left or right side (determining which player is moving) and I can use this to move each player individually, but I can't make them do this at the same time.
This is how I currently have my movement set up:
PlayerPaddle playerOnePaddle = ((GameScreen) currentScreen).getPlayerOnePaddle();
PlayerPaddle playerTwoPaddle = ((GameScreen) currentScreen).getPlayerTwoPaddle();
Vector2 touchPos = new Vector2(Gdx.input.getX(), Gdx.input.getY() + playerOnePaddle.height / 2);
if (Gdx.input.getX() < Gdx.graphics.getWidth() / 2)
{
playerOnePaddle.pos.y = Gdx.graphics.getHeight() - touchPos.y;
}
if (Gdx.input.getX() > Gdx.graphics.getWidth() / 2)
{
playerTwoPaddle.pos.y = Gdx.graphics.getHeight() - touchPos.y;
}
This works with individual input, meaning that I can tap the left of the screen and move the left player, I can tap the right of the screen and move the right player, but I can't move each player at the same time, which would defeat the point of the game. I need specific examples of how to implement this, as my experience with LibGDX input is very limited and after searching around I wasn't able to find any correct ways to do this. I thought about multithreading the second input, but that would just make the code messy and make the logic unsymmetrical