【问题标题】:Libgdx Sprite not moving smoothlyLibgdx Sprite 移动不顺畅
【发布时间】:2016-07-02 16:47:10
【问题描述】:

我遇到了一个问题,当我移动我的精灵时它停止了,我必须再次按下才能让精灵再次移动。

我想要的是当用户按住他们的输入时,角色会继续向输入的方向移动,而不是在输入会使角色移动一点点并且需要手指抬起并再次输入的那一刻发生的事情.我已附上以下内容以尝试帮助解释。

目前正在发生的事情:

我想要什么:

我的代码如下,请告知为什么会这样,如果可能的话我需要改变什么

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


        if (Gdx.input.isTouched()) {

          player.b2body.applyLinearImpulse(new Vector2(5.1f, 0), player.b2body.getWorldCenter(), true);

            }

        }
            return true;
          }

这里还有一个类似的代码示例:https://github.com/BrentAureli/SuperMario/blob/master/core/src/com/brentaureli/mariobros/Screens/PlayScreen.java

【问题讨论】:

    标签: java android libgdx sprite ontouch


    【解决方案1】:

    我不确定,但我认为您的问题是您从 touchDown 方法调用此代码。我认为这个方法只在发生触摸/点击时被调用一次。为了您想要的结果,移动代码

    if (Gdx.input.isTouched()) {
    
              player.b2body.applyLinearImpulse(new Vector2(5.1f, 0), player.b2body.getWorldCenter(), true);
    
                }
    
            }
    

    进入你的游戏循环/render 方法

    【讨论】:

    • 好收获!谢谢朋友。
    猜你喜欢
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2016-06-21
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多