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

        <bdo id='qquCp'></bdo><ul id='qquCp'></ul>

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

        <tfoot id='qquCp'></tfoot>

        LibGDX - 向上滑动或向右滑动等?

        时间:2023-05-19

            <bdo id='hqOl3'></bdo><ul id='hqOl3'></ul>

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

                    <tbody id='hqOl3'></tbody>

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

                2. <tfoot id='hqOl3'></tfoot>
                  <i id='hqOl3'><tr id='hqOl3'><dt id='hqOl3'><q id='hqOl3'><span id='hqOl3'><b id='hqOl3'><form id='hqOl3'><ins id='hqOl3'></ins><ul id='hqOl3'></ul><sub id='hqOl3'></sub></form><legend id='hqOl3'></legend><bdo id='hqOl3'><pre id='hqOl3'><center id='hqOl3'></center></pre></bdo></b><th id='hqOl3'></th></span></q></dt></tr></i><div id='hqOl3'><tfoot id='hqOl3'></tfoot><dl id='hqOl3'><fieldset id='hqOl3'></fieldset></dl></div>
                3. 本文介绍了LibGDX - 向上滑动或向右滑动等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  触摸区域http://imageshack.us/a/img836/2909/swipe1.png

                  在绿色区域,用户可以向上、向右、向下、向左滑动.我现在怎么能得到例如向上滑动?或向下滑动?或向右滑动或向左滑动?例如如何获取字符串 -> input = getSwiped();-> 输入然后向上,或向右,或向下,或向左

                  In the green area the user can swipe up, right, down, left. How can I now get e.g. swipe Up? or swipe Down? or swipe right or swipe left? e.g. how to get a String -> input = getSwiped(); -> input is then Up, or right, or down, or left

                  并且用户可以触摸两个按钮.1 或 2.1 是鸭子,2 是跳跃.

                  And the user can touch two buttons. 1 or 2. 1 is for duck and 2 is for jump.

                  我想同时检查这些输入.用户可以同时触摸和向上滑动.

                  I want to check this inputs at the same time. The user can touch and also swipe Up at the same moment.

                  我知道有一个 GestureDetector.我查看了代码,但不知道如何使用滑动部分.

                  I know there is a GestureDetector. I looked at the code, but no clue how can I use the swipe part.

                  我知道一点如何检查按钮.问题只在这里 -> 如何同时检查输入以及如何向上滑动或向右滑动等.

                  I know a little bit how to check the buttons. The problem is only here -> How to check the inputs at the same time and how get Swipe Up, or Swipe right etc.

                  我搜索了一个发现如何检查多点触控:

                  I searched an found how to check Multitouching:

                  for (int i = 0; i < 10; i++) {
                      if (Gdx.input.isTouched(i) == false) continue;
                      float x = Gdx.input.getX(i);
                      float y = Gdx.graphics.getHeight() - Gdx.input.getY(i) - 1;
                      //...
                  }
                  

                  推荐答案

                  这解释了一种很好的方法来实现一个系统来检测滑动的方向.我将它发布在这里,因为将来该文章可能会丢失:

                  This explain a very good way to implement a system to detect the direction of a swipe. I'll post it here because the article may be lost in the future:

                  创建一个类名 SimpleDirectionGestureDetector

                  Create a class name SimpleDirectionGestureDetector

                  public class SimpleDirectionGestureDetector extends GestureDetector {
                  public interface DirectionListener {
                      void onLeft();
                  
                      void onRight();
                  
                      void onUp();
                  
                      void onDown();
                  }
                  
                  public SimpleDirectionGestureDetector(DirectionListener directionListener) {
                      super(new DirectionGestureListener(directionListener));
                  }
                  
                  private static class DirectionGestureListener extends GestureAdapter{
                      DirectionListener directionListener;
                  
                      public DirectionGestureListener(DirectionListener directionListener){
                          this.directionListener = directionListener;
                      }
                  
                      @Override
                      public boolean fling(float velocityX, float velocityY, int button) {
                          if(Math.abs(velocityX)>Math.abs(velocityY)){
                              if(velocityX>0){
                                      directionListener.onRight();
                              }else{
                                      directionListener.onLeft();
                              }
                          }else{
                              if(velocityY>0){
                                      directionListener.onDown();
                              }else{                                  
                                      directionListener.onUp();
                              }
                          }
                          return super.fling(velocityX, velocityY, button);
                      }
                  
                  }
                  
                  }
                  

                  在 LibGdx 应用程序的 create() 函数上,将其用于激活游戏的手势处理:

                  On the create() function of the LibGdx application, put this to activate gesture handling for your game:

                  Gdx.input.setInputProcessor(new SimpleDirectionGestureDetector(new SimpleDirectionGestureDetector.DirectionListener() {
                  
                  @Override
                  public void onUp() {
                  
                  }
                  
                  @Override
                  public void onRight() {
                  
                  }
                  
                  @Override
                  public void onLeft() {
                  
                  }
                  
                  @Override
                  public void onDown() {
                  
                  }
                  }));
                  

                  这篇关于LibGDX - 向上滑动或向右滑动等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:了解 libgdx 下一篇:LibGDX 0.9.9 - 在环境中应用立方体贴图

                  相关文章

                  最新文章

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

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

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