【问题标题】:How to have Gdx.input.istouched return false when I pressed on a button?当我按下按钮时,如何让 Gdx.input.istouched 返回 false?
【发布时间】:2017-08-06 08:31:03
【问题描述】:

我是游戏编程的新手,对 libGDX 更是如此。如果有人可以看看这个问题,我将不胜感激。

简单地说,我现在正在制作一个飞扬的小鸟游戏。我使用 Gdx.input.istouched 检查屏幕的任何点是否刚刚被触摸。如果是这样,那么其余代码调用bird.jump()。在我添加了一个暂停按钮之前效果很好。现在小鸟在按钮能够暂停游戏之前跳跃。按下暂停键时如何让游戏暂停而不让小鸟跳跃?

如果需要,您可以查看我的代码,无论如何我都会将其开源。这是我的code.

【问题讨论】:

  • 您应该阅读提问指南,特别是关于如何提供如何创建最小、完整和可验证的示例的指南。您还应该在问题中包含相关代码。
  • 不要使用justTouched。使用 InputListener。

标签: libgdx


【解决方案1】:

使用InputProcessor 并覆盖touchDown(..) 监听器方法。此外,您需要将该侦听器与您的 hud 阶段 InputProcessor 混合。

InputMultiplexer inputMultiplexer=new InputMultiplexer();
    inputMultiplexer.addProcessor(new InputAdapter() {

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

            bird.jump();
            return super.touchDown(screenX, screenY, pointer, button);
        }
    });

inputMultiplexer.addProcessor(scoreAndButton.stage);
Gdx.input.setInputProcessor(inputMultiplexer);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-07
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2020-01-09
    • 2021-12-18
    相关资源
    最近更新 更多