【问题标题】:LibGDX - InputProcessor - if user draggs finger from button which represents moving on X, to button which represents moving on YLibGDX - InputProcessor - 如果用户将手指从代表在 X 上移动的按钮拖动到代表在 Y 上移动的按钮
【发布时间】:2014-12-10 14:50:32
【问题描述】:

所以,我正在为 android 游戏创建一个游戏,所以在我的 Touching 类(实现 InputProcessor)中它看起来像:

public class Touching implements InputProcessor{

    int y = 0;
    int x = 0;

    public boolean touchDown(int screenX, int screenY, int pointer, int button) {

        x = Gdx.input.getX();
        y = Gdx.input.getY();

    if (x > 122 && x < 202 && y > 620 && y < 700 )
    {
        Core.player1.anmov(2); //button 1
    }

    if ( x > 122 && x < 202 && y > 520 && y < 600)
    {
        Core.player1.anmov(1); //button 2
    }

    if (x > 20 && x < 100 && y > 620 && y < 700)
    {
        Core.player1.anmov(3); //button 3
    }

    if (x > 222 && x < 302 && y > 620 && y < 700)
    {
        Core.player1.anmov(4); // button 4
    }

        return true;
    }

    public boolean touchUp(int screenX, int screenY, int pointer, int button) {


        x = Gdx.input.getX();
        y = Gdx.input.getY();
        if (x > 122 && x < 202 && y > 620 && y < 700)
        {
            Core.player1.anmov(7); // button 1
        }

        if ( x > 122 && x < 202 && y > 520 && y < 600)
        {
            Core.player1.anmov(8); // button 2
        }

        if (x > 20 && x < 100 && y > 620 && y < 700)
        {
            Core.player1.anmov(5); // button 3
        }

        if (x > 222 && x < 302 && y > 620 && y < 700)
        {
            Core.player1.anmov(6); // button 4
        }

        return false;
    }

    public boolean touchDragged(int screenX, int screenY, int pointer) {
x = Gdx.input.getX();
y = Gdx.input.getY();

        return true;
    }

所以现在,如果我触摸代表在 X 上移动的按钮,拖动到代表在 Y 上移动的按钮,它仍然在 X 上移动,直到我的手指离开屏幕(touchUP 正在调用),然后,它站着,它在 Y 上不动..

有人可以帮帮我吗?我认为这是一个非常原始的方法,但我找不到解决方案。

【问题讨论】:

  • 这是做你想做的事的坏方法......
  • @BoldijarPaul 这是评论问题的糟糕方式。尽量有建设性。
  • @BoldijarPaul 是对的,你不需要一个单独的类来处理你想要的简单事情。我只会在播放器类中编写运动。更糟糕的是你处理运动本身的方式与全球玩家领域。
  • @MennoGouw 我没有给他降价之类的,这就是问题所在,他正试图以错误的方式做某事。有大约 1000 种方法可以做到这一点..是的,也许我应该告诉他一个想法..但我不知道他的编程知识有多好..
  • @BoldijarPaul 只是说“这很糟糕”是没有用的,没有帮助任何人,只是乱扔问题。我会说这个用户介于绝对初学者和初学者之间。

标签: android libgdx touch draggable


【解决方案1】:

我可能会在播放器类更新方法本身中使用类似的东西

//Declare velocity on top so you just have to change this to fine tune speed.
float velocity = 10;

if (Gdx.input.isTouched()) //isTouched should register as long as a screen is touched, you can use pointers for multiple fingers.
{
    if (touch within button) //just use Gdx.input.getX / Gdx.input.getY
    {
        position.X += velocity * Gdx.graphics.getDeltaTime();
    {
     //do for each button
}

我自己从未使用过拖动屏幕按钮,但理论上这应该可以工作,因为isTouched 会在触摸长屏幕时注册。 Gdx.input.getX/Y 应该更新。你可能有一些只运行一次并继续移动你的播放器直到发布注册的东西。

【讨论】:

    猜你喜欢
    • 2014-03-15
    • 1970-01-01
    • 2017-06-25
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多