加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何检测正在使用的手指数量?

发布时间:2020-12-15 04:30:03 所属栏目:Java 来源:网络整理
导读:我正在使用Libgdx进行游戏,我需要知道用户是否正在使用两根手指以及是否将它们放置在正确的位置.一根手指应位于屏幕右侧,另一根手指应位于屏幕左侧. 解决方法 没有使用任何监听器的最简单的解决方案是迭代一些指针计数并调用简单的Gdx.input.isTouched() –
我正在使用Libgdx进行游戏,我需要知道用户是否正在使用两根手指以及是否将它们放置在正确的位置.一根手指应位于屏幕右侧,另一根手指应位于屏幕左侧.

解决方法

没有使用任何监听器的最简单的解决方案是迭代一些指针计数并调用简单的Gdx.input.isTouched() – 你必须设置一些“最大指针计数”但是嘿 – 人们通常只有20个手指:)

final int MAX_NUMBER_OF_POINTERS = 20;
    int pointers = 0;

    for(int i = 0; i < MAX_NUMBER_OF_POINTERS; i++)
    {  
        if( Gdx.input.isTouched(i) ) pointers++;
    }

    System.out.println( pointers );

由于参考:

Whether the screen is currently touched by the pointer with the given index. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen,e.g. 0 is the first finger,1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.

你也可以通过使用Gdx.input.getX()和Gdx.input.getY()来轻松触摸指针的位置

final int MAX_NUMBER_OF_POINTERS = 20;
    int pointers = 0;

    for(int i = 0; i < MAX_NUMBER_OF_POINTERS; i++)
    {  
        if( Gdx.input.isTouched(i) )
        {
            x = Gdx.input.getX(i);
            y = Gdx.input.getY(i)
        }
    }

然后你可以把它放到数组中

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读