【问题标题】:LibGDX multi-touch implementation, game developmentLibGDX多点触控实现,游戏开发
【发布时间】:2014-08-21 21:40:59
【问题描述】:

我目前正在使用 LibGdx 开发一款安卓游戏。我正在尝试让多点触控功能发挥作用,因为游戏要求玩家有一个拇指来控制角色,另一个拇指来点击按钮。

代码:

for (int i = 0; i < 2; i++) { 
            if (Gdx.input.isTouched(i)) {
                final int iX = Gdx.input.getX(i);
                if (iX > screenwidth - screenwidth / 14) {
                    buttontouch = true;
                } else {
                    buttontouch = false;
                }

                if (iX <= screenwidth - screenwidth / 14) {
                    playertouch = true;
                }else{
                    playertouch = false;
                }

            }
        }


if (playertouch){
etc...
}
if(buttontouch){
etc...
}

可以移动播放器并按下按钮,但不能同时 :( ...这是我需要的。

任何帮助将不胜感激!提前致谢。

【问题讨论】:

    标签: java android libgdx multi-touch


    【解决方案1】:

    应该在for 圆圈内调用移动角色的逻辑。您应该在每次循环迭代时移动您的角色(如果单击按钮)像这样:

    for (int i = 0; i < 2; i++) { 
            if (Gdx.input.isTouched(i)) {
                final int iX = Gdx.input.getX(i);
                if (iX > screenwidth - screenwidth / 14) {
                    buttontouch = true;
                } else {
                    buttontouch = false;
                }
    
                if (iX <= screenwidth - screenwidth / 14) {
                    playertouch = true;
                }else{
                    playertouch = false;
                }
            }
    //Logic here!
    if (playertouch){
    etc...
    }
    if(buttontouch){
    etc...
    }
        }
    

    【讨论】:

    • 感谢您的帮助,我进行了更改,但每个功能仍然只能单独工作。任何想法:S
    【解决方案2】:

    好的,我似乎已经找到了答案。 添加了

    if (Gdx.input.isTouched(i)) {
    

    在每个布尔 if 的下方

    for (int i = 0; i < 2; i++) { 
            if (Gdx.input.isTouched(i)){
                final int iX = Gdx.input.getX(i);
                if (iX > screenwidth - screenwidth / 14) {
                    buttontouch = true;
                } else {
                    buttontouch = false;
                }
    
                if (iX <= screenwidth - screenwidth / 14) {
                    playertouch = true;
                }else{
                    playertouch = false;
                }
            }
      }
    //Logic here!
    if (playertouch){
    if (Gdx.input.isTouched(i)) {
    etc...
    }
    }
    if(buttontouch){
    if (Gdx.input.isTouched(i)) {
    etc...
    }
    }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多