我试图用两根手指同时触摸两个矩形。我该如何实现呢?
答案 0 :(得分:1)
没关系,我找到了解决这个问题的方法:
public void detectTwoRectangleTouching() {
if(Gdx.input.isTouched(0)){
int x = Gdx.input.getX(0);
int y = Gdx.input.getY(0);
if(rectangle1.contain(x,y))
isRectangle1Touched = true;
else
isRectangle1Touched = false;
if(rectangle2.contain(x,y))
isRectangle2Touched = true;
else
isRectangle2Touched = false;
}else {
isRectangle1Touched = false;
isRectangle2Touched = false;
}
if(Gdx.input.isTouched(1)){
int x = Gdx.input.getX(1);
int y = Gdx.input.getY(1);
if(rectangle1.contain(x,y))
isRectangle1Touched = true;
if(rectangle2.contain(x,y))
isRectangle2Touched = true;
}
if(isRectangle1Touched && isRectangle2Touched) {
// the two rectangle are pressed !!!
}
if(!isRectangle1Touched && !isRectangle2Touched) {
// the two rectangle are released !!!
}
}