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

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

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

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

      1. 使用 libgdx 进行触摸滚动

        时间:2023-05-19
        <tfoot id='cfif9'></tfoot>
      2. <small id='cfif9'></small><noframes id='cfif9'>

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

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

                  <bdo id='cfif9'></bdo><ul id='cfif9'></ul>
                • 本文介绍了使用 libgdx 进行触摸滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试在 libgdx 游戏中实现触摸滚动.我有一张宽幅图像,它是房间的全景图.我希望能够滚动图像,以便用户可以看到房间周围.我有它,以便我可以滚动一定距离,但是当注册一个新的 touchDragged 事件时,图像会移回原始位置.

                  I'm trying to implement touch scrolling in a libgdx game. I have a wide image that is a panorama of a room. I want to be able to scroll the image so the user can see around the room. I have it so that I can scroll a certain distance but when a new touchDragged event is registered the image is moved back to the original position.

                  这就是我的实现方式

                  public class AttackGame implements ApplicationListener {
                  
                  AttackInputProcessor inputProcessor;
                  Texture backgroundTexture; 
                  TextureRegion region;
                  OrthographicCamera cam;
                  SpriteBatch batch;
                  float width;
                  float height;
                  float posX;
                  float posY;
                  
                  @Override
                  public void create() {
                      posX = 0;
                      posY = 0;
                      width = Gdx.graphics.getWidth();
                      height = Gdx.graphics.getHeight();  
                      backgroundTexture = new Texture("data/pancellar.jpg");
                      region = new TextureRegion(backgroundTexture, 0, 0, width, height);
                      batch = new SpriteBatch();
                  
                  }
                  
                  @Override
                  public void resize(int width, int height) {
                      cam = new OrthographicCamera();
                      cam.setToOrtho(false, width, height);
                      cam.translate(width / 2, height / 2, 0);
                      inputProcessor = new AttackInputProcessor(width, height, cam);
                      Gdx.input.setInputProcessor(inputProcessor);
                  
                  }
                  
                  @Override
                  public void render() {
                  
                      Gdx.gl.glClearColor(0,0,0,1);
                      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);    
                      batch.setProjectionMatrix(cam.combined);
                      batch.begin();
                      batch.draw(backgroundTexture, 0, 0, 2400, 460);
                      batch.end();
                  
                  }
                  
                  @Override
                  public void pause() {
                      // TODO Auto-generated method stub
                  
                  }
                  
                  @Override
                  public void resume() {
                      // TODO Auto-generated method stub
                  
                  }
                  
                  @Override
                  public void dispose() {
                      backgroundTexture.dispose();
                  
                  }
                  

                  }

                  在输入处理器中

                  @Override
                  public boolean touchDragged(int screenX, int screenY, int pointer) {
                  
                      cam.position.set(screenX, posY / 2, 0);
                      cam.update();
                      return false;
                  }
                  

                  在这个问题LibGdx How to Scroll using OrthographicCamera?.但是它并没有真正解决我的问题.

                  I got this far with help from this question LibGdx How to Scroll using OrthographicCamera?. However it doesn't really solve my problem.

                  我认为问题在于 touchDragged corodinates 不是世界坐标,但我尝试取消投影相机但没有任何效果.

                  I think the problem is with the touchDragged corodinates not being world coordinates but I have tried unprojecting the camera with no effect.

                  我已经为此苦苦挣扎了几个星期,非常感谢您对此提供帮助.

                  I have been struggling with this for a few weeks and I would really appreciate some help on this.

                  提前致谢.

                  推荐答案

                  我最近做了一些你想要的.这是我用于移动地图的输入类,您只需为您的 'cam' 更改我的 'stage.getCamera()':

                  I recently did something as what you want. This is my Input class that I use for move the map, you only need to change my 'stage.getCamera()' for your 'cam':

                  public class MapInputProcessor implements InputProcessor {
                      Vector3 last_touch_down = new Vector3();
                  
                      ...
                  
                      public boolean touchDragged(int x, int y, int pointer) {
                          moveCamera( x, y );     
                          return false;
                      }
                  
                      private void moveCamera( int touch_x, int touch_y ) {
                          Vector3 new_position = getNewCameraPosition( touch_x, touch_y );
                  
                          if( !cameraOutOfLimit( new_position ) )
                              stage.getCamera().translate( new_position.sub( stage.getCamera().position ) );
                  
                          last_touch_down.set( touch_x, touch_y, 0);
                      }
                  
                      private Vector3 getNewCameraPosition( int x, int y ) {
                          Vector3 new_position = last_touch_down;
                          new_position.sub(x, y, 0);
                          new_position.y = -new_position.y;
                          new_position.add( stage.getCamera().position );
                  
                          return new_position;
                      }
                  
                      private boolean cameraOutOfLimit( Vector3 position ) {
                          int x_left_limit = WINDOW_WIDHT / 2;
                          int x_right_limit = terrain.getWidth() - WINDOW_WIDTH / 2;
                          int y_bottom_limit = WINDOW_HEIGHT / 2;
                          int y_top_limit = terrain.getHeight() - WINDOW_HEIGHT / 2;
                  
                          if( position.x < x_left_limit || position.x > x_right_limit )
                              return true;
                          else if( position.y < y_bottom_limit || position.y > y_top_limit )
                              return true;
                          else
                            return false;
                  }
                  
                  
                      ...
                  }
                  

                  这是结果:http://www.youtube.com/watch?feature=player_embedded&v=g1od3YLZpww

                  这篇关于使用 libgdx 进行触摸滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:通过 AssetManager 加载时无法使用 libgdx 在 IOS 中加 下一篇:是否可以在 libgdx 中扭曲演员

                  相关文章

                  最新文章

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

                      <tfoot id='tGdgR'></tfoot>

                      • <bdo id='tGdgR'></bdo><ul id='tGdgR'></ul>
                    1. <legend id='tGdgR'><style id='tGdgR'><dir id='tGdgR'><q id='tGdgR'></q></dir></style></legend>

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