Libgdx SpriteBatch 绘制 Actors,但不绘制其他纹理

Libgdx SpriteBatch draws Actors, but not other Textures

我已经有一段时间没有使用 LibGdx,所以我觉得我只是遗漏了一些明显的东西。

我在 MyGdxGame 中的渲染方法如下所示,调用舞台绘制自身(连同它的演员),然后我尝试绘制一组纹理以用于调试目的。

@Override
    public void render()
    {        
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        StageManager.getCurrentStage().act();

        spriteBatch.begin();
        StageManager.getCurrentStage().draw();
        for(int i = 0; i < 100; i++) 
        {
            spriteBatch.draw(TextureManager.getPlayerTexture(), 50*i, 50*i);
        }
    }

舞台连同它的一个演员一起被绘制,但其他纹理没有被绘制。

我尝试过的方法:在舞台摄像机外设置批量投影矩阵(在调用 update 之后),确保纹理坐标应该可见。

演员从同一个 TextureManager.getPlayerTexture 获取纹理,所以我认为这不是纹理问题。

我还应该检查什么来绘制纹理?

通常,您的代码会导致 RuntimeException,因为您在绘制舞台之前在批处理上调用 begin。但是由于您实际上有两个 sprite 批次(一个在舞台内部,因为您没有与它共享原始图形),因此不会发生实际错误。

您在绘制纹理后错过了对 spriteBatch.end() 的调用。并且对 spriteBatch.begin() 的调用需要在 stage.draw().

之后移动

并且您应该将该 sprite 批次传递给 Stage 构造函数,因为拥有多个 sprite 批次是一种浪费。每个精灵批次使用相当数量的内存并编译一个着色器。