How to detect touching/releasing two objects with two pointers

不想你离开。 提交于 2019-12-25 01:16:49

问题


I'm trying to touch two rectangle at the same time using two fingers. How can i implements that ?


回答1:


Never mind I find a solution to this problem :

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 !!!
        }
    }


来源:https://stackoverflow.com/questions/36285343/how-to-detect-touching-releasing-two-objects-with-two-pointers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!