# How do I detect if two sprites are being touched at the same time?

How do I detect if two sprites are being touched at the same time?

I was able to detect one sprite, but not if another sprite is being touched by the second pointer.

if(spr.getBoundingRectangles.contain(x,y))
{
//do this
}


Then, I created two Vector3 variables for the pointer coordinates, before iterating to each pointer.

for(int i = 0; i < Constants.MAX_POINTERS; i++)
{
if(Gdx.input.isTouched(i))
{
xy.set(Gdx.input.getX(i), Gdx.input.getY(i), 0);
xy1.set(Gdx.input.getX(i), Gdx.input.getY(i), 0);
WorldRenderer.camera.unproject(xy);
WorldRenderer.camera.unproject(xy1);

if(Spr.getBoundingRectangle().contains(xy.x, xy.y) &&
Spr1.getBoundingRectangle().contains(xy.x, xy.y))
{
score += 1;
}
}
}


What happens is that xy and xy1 are always the same, so when I touch the screen with the second pointer, they will just both switch to the new coordinates instead of xy and xy1 having different x and y values.

• Your calculations of xy and xy1 are identical; they happen at the same time with the same input parameters. One solution is to create an array of size MAX_POINTERS, then calculate xy[i].set( Gdx.input.getX(i), Gdx.input.getY(i), 0 ); WorldRenderer.camera.unproject( xy[i] ); Oct 10 '15 at 16:01