【问题标题】:LibGDX dragging a textureLibGDX 拖动纹理
【发布时间】:2014-11-10 22:45:41
【问题描述】:

我正在尝试使用 LibGDX 和 Java,如果用户的手指正在触摸另一个纹理,我希望根据用户的手指位置使纹理沿 x 轴移动。下面是我的代码,它只在手指向右移动时才有效

game.batch.begin();
game.batch.draw(userCar, carCord.x, carCord.y);
game.batch.draw(touchBound, touchCord.x, touchCord.y);
game.batch.end();

if (Gdx.input.isTouched()) {
    Vector3 touchPos = new Vector3();
    Rectangle textureBounds=new Rectangle(touchCord.x,touchCord.y,touchCord.width,touchCord.height);
    touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
    camera.unproject(touchPos);
    if(textureBounds.contains(touchPos.x,touchPos.y) {
        carCord.x = touchPos.x;
    }
}

【问题讨论】:

    标签: java libgdx game-physics


    【解决方案1】:

    嗯,有一些细节需要考虑。

    1) 你应该提供更多关于你的问题的信息。

    2) game.batch.draw(touchBound, touchCord.x, touch.y);touch.y 而不是 touchCord.y 看起来真的很可疑。看看吧。

    3) 根据您如何处理这些位置和纹理大小,您不应该取消投影触摸位置,或者您应该相应地分配纹理 x。

    4) 还要记住 Y 轴的方向。它可能指向上方,您会询问触摸是否在其内部且坐标错误。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多