This is my first attempt in game development. I just started experimenting libgdx and understanding the different aspects of game programming. I looked at the sample project
I've solved the problem by making an invisible rectangle which will follow the tap location and I made an if statement checking for overlapping of the invisible rectangle and checking for if the screen was just tapped.
Here is the code:
if(Gdx.input.isTouched()) {
Vector3 pointerPos = new Vector3();
pointerPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
cam.unproject(pointerPos);
touchPos.x = pointerPos.x /*+ 64 / 2*/;
touchPos.y = pointerPos.y /*+ 64 / 2*/;
}
Iterator iter = raindrops.iterator();
while(iter.hasNext()) {
Rectangle raindrop = iter.next();
raindrop.y -= 300 * Gdx.graphics.getDeltaTime();
if(raindrop.y + 64 < 0) {
iter.remove();
}
if(raindrop.overlaps(touchPos) && Gdx.input.justTouched()) {
iter.remove();
dropSound.play();
}
all of this code is in the render method.
P.S: Change raindrops to the fly objects you want