0

我目前在 box2d 游戏区域上渲染 UI 时遇到问题。截至目前,该按钮呈现在屏幕的角落,但不会对点击做出反应,因为似乎屏幕认为它不存在。只有它的图片。下面是屏幕工作原理的代码。正在呈现什么顺序。在 spritebatch 开始和结束之前和之后的凸轮缩放、更新和设置是导致精灵在角落的测试,但它仍然没有做任何事情。我很困惑,希望能得到一些关于如何以一种好的方式处理渲染的建议。

public synchronized void render(float delta) {
    getCamControll().update();

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // RENDER SPRITES
    batch.setProjectionMatrix(cam.combined);
    batch.begin();

    Iterator<Renderable> itr = renderables.iterator();
    while (itr.hasNext()) {
        Renderable r = itr.next();
        r.render(batch);
    }

    batch.end();

    // RENDER DEBUG
    sr.setProjectionMatrix(cam.combined);
    sr.begin(ShapeType.Line);
    for (Renderable r : renderables) {
        r.debug(sr);
    }
    sr.end();

    // RENDER GUI
    float camzoom = cam.zoom;
    Vector3 camPos = cam.position.cpy();
    cam.zoom = 1;
    cam.position.set(Vector2.Zero, cam.position.z);
    cam.update();
    batch.setProjectionMatrix(new Matrix4());
    if (stage != null) {
        batch.begin();
        stage.draw();
        Array<Actor> actors = stage.getActors();
        batch.end();
    }

    cam.zoom = camzoom;
    cam.position.set(camPos);
    cam.update();
}
4

1 回答 1

4

您需要正确设置输入处理程序,即在您的设置/初始化代码中的某个位置(在您创建阶段之后)您需要:

    Gdx.input.setInputProcessor(stage);

如果 box2d(或其他任何东西)除了场景之外还需要处理输入,您应该查看 Libgdx 的 InputMultiplexer 以组合输入处理程序。

于 2014-02-25T12:20:26.143 回答