<legend id='YO6LP'><style id='YO6LP'><dir id='YO6LP'><q id='YO6LP'></q></dir></style></legend>

  1. <tfoot id='YO6LP'></tfoot>
      <bdo id='YO6LP'></bdo><ul id='YO6LP'></ul>
  2. <small id='YO6LP'></small><noframes id='YO6LP'>

      <i id='YO6LP'><tr id='YO6LP'><dt id='YO6LP'><q id='YO6LP'><span id='YO6LP'><b id='YO6LP'><form id='YO6LP'><ins id='YO6LP'></ins><ul id='YO6LP'></ul><sub id='YO6LP'></sub></form><legend id='YO6LP'></legend><bdo id='YO6LP'><pre id='YO6LP'><center id='YO6LP'></center></pre></bdo></b><th id='YO6LP'></th></span></q></dt></tr></i><div id='YO6LP'><tfoot id='YO6LP'></tfoot><dl id='YO6LP'><fieldset id='YO6LP'></fieldset></dl></div>

      如何在 Libgdx 中跟踪多个触摸事件?

      时间:2023-05-20
      <tfoot id='Iqcx2'></tfoot>

      <small id='Iqcx2'></small><noframes id='Iqcx2'>

    1. <legend id='Iqcx2'><style id='Iqcx2'><dir id='Iqcx2'><q id='Iqcx2'></q></dir></style></legend>

        <tbody id='Iqcx2'></tbody>

      <i id='Iqcx2'><tr id='Iqcx2'><dt id='Iqcx2'><q id='Iqcx2'><span id='Iqcx2'><b id='Iqcx2'><form id='Iqcx2'><ins id='Iqcx2'></ins><ul id='Iqcx2'></ul><sub id='Iqcx2'></sub></form><legend id='Iqcx2'></legend><bdo id='Iqcx2'><pre id='Iqcx2'><center id='Iqcx2'></center></pre></bdo></b><th id='Iqcx2'></th></span></q></dt></tr></i><div id='Iqcx2'><tfoot id='Iqcx2'></tfoot><dl id='Iqcx2'><fieldset id='Iqcx2'></fieldset></dl></div>

        • <bdo id='Iqcx2'></bdo><ul id='Iqcx2'></ul>

                本文介绍了如何在 Libgdx 中跟踪多个触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我正在使用 Libgdx 制作赛车游戏.我想触摸屏幕右侧的一半来加速,同时在不移除之前的触摸点的情况下再次触摸屏幕左侧的另一个来射击.我无法检测到后来的接触点.

                I am making a racing game using Libgdx. I want to touch the half right side of screen to speed up, at the same time without removing previous touch point touch again another on the left side of the screen to fire a shot. I am unable to detect later touch points.

                我已经搜索并获得了 Gdx.input.isTouched(int index) 方法,但无法确定如何使用它.我的屏幕触摸代码是:

                I have searched and get Gdx.input.isTouched(int index) method, but cannot determin how to use it. My screen touch code is:

                if(Gdx.input.isTouched(0) && world.heroCar.state != HeroCar.HERO_STATE_HIT){
                    guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
                    if (OverlapTester.pointInRectangle(rightScreenBounds, touchPoint.x, touchPoint.y)) {
                       world.heroCar.state = HeroCar.HERO_STATE_FASTRUN;
                       world.heroCar.velocity.y = HeroCar.HERO_STATE_FASTRUN_VELOCITY;
                    }
                } else {
                    world.heroCar.velocity.y = HeroCar.HERO_RUN_VELOCITY;
                }
                
                if (Gdx.input.isTouched(1)) {
                    guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
                    if (OverlapTester.pointInRectangle(leftScreenBounds, touchPoint.x, touchPoint.y)) {
                       world.shot();
                    }
                }
                

                推荐答案

                你会想要使用 Gdx.input.getX(int index) 方法.整数 index 参数表示活动指针的 ID.要正确使用它,您需要遍历所有可能的指针(如果两个人在平板电脑上有 20 根手指?).

                You'll want to use the Gdx.input.getX(int index) method. The integer index parameter represents the ID of an active pointer. To correctly use this, you will want to iterate through all the possible pointers (in case two people have 20 fingers on the tablet?).

                类似这样的:

                boolean fire = false;
                boolean fast = false;
                final int fireAreaMax = 120; // This should be scaled to the size of the screen?
                final int fastAreaMin = Gdx.graphics.getWidth() - 120;
                for (int i = 0; i < 20; i++) { // 20 is max number of touch points
                   if (Gdx.input.isTouched(i)) {
                      final int iX = Gdx.input.getX(i);
                      fire = fire || (iX < fireAreaMax); // Touch coordinates are in screen space
                      fast = fast || (iX > fastAreaMin);
                   }
                }
                
                if (fast) {
                   // speed things up
                } else {
                   // slow things down
                }
                
                if (fire) {
                   // Fire!
                }
                

                另一种方法是设置 InputProcessor 来获取输入事件(而不是像上面的例子那样轮询"输入).当指针进入其中一个区域时,您必须跟踪该指针的状态(以便在它离开时清除它).

                An alternative approach is to setup an InputProcessor to get input events (instead of "polling" the input as the above example). And when a pointer enters one of the areas, you would have to track that pointer's state (so you could clear it if it left).

                这篇关于如何在 Libgdx 中跟踪多个触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:我怎么能每秒都做某事?[LibGDX] 下一篇:android.os.Bundle 无法在 libgdx Android 项目中解析

                相关文章

                最新文章

              1. <i id='Dl7ph'><tr id='Dl7ph'><dt id='Dl7ph'><q id='Dl7ph'><span id='Dl7ph'><b id='Dl7ph'><form id='Dl7ph'><ins id='Dl7ph'></ins><ul id='Dl7ph'></ul><sub id='Dl7ph'></sub></form><legend id='Dl7ph'></legend><bdo id='Dl7ph'><pre id='Dl7ph'><center id='Dl7ph'></center></pre></bdo></b><th id='Dl7ph'></th></span></q></dt></tr></i><div id='Dl7ph'><tfoot id='Dl7ph'></tfoot><dl id='Dl7ph'><fieldset id='Dl7ph'></fieldset></dl></div>

                <small id='Dl7ph'></small><noframes id='Dl7ph'>

                <legend id='Dl7ph'><style id='Dl7ph'><dir id='Dl7ph'><q id='Dl7ph'></q></dir></style></legend>
              2. <tfoot id='Dl7ph'></tfoot>
                  <bdo id='Dl7ph'></bdo><ul id='Dl7ph'></ul>