I started using libGDX soon, and I was making a game that has water droplets falling from the top of the screen and the user should tap them before they do touch the bottom of the screen. I have a problem in knowing if the user did tap the droplet to do something.
This is my Render method:
Gdx.gl.glClearColor(0/255.0f, 0/255.0f, 100/255.0f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.update();
if (TimeUtils.millis() - lastDrop > 333)
spawnRainDrop();
Iterator<Rectangle> iter = raindrops.iterator();
while (iter.hasNext()) {
Rectangle raindrop = iter.next();
raindrop.y -= 300 * Gdx.graphics.getDeltaTime();
if (raindrop.y + 64 < 0) {
iter.remove();
}
if (Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
cam.unproject(touchPos);
if (Gdx.input.getX() == raindrop.x + 64 / 2 && Gdx.input.getY() == raindrop.y + 64 / 2) {
System.out.println("Tapped");
}
}
}
The tapping code doesn't seem to work.
I would really appreciate if someone did explain their answer. Thanks