libGdx:存在阶段时不会绘制Sprite

tom*_*met 5 java android libgdx

我确定我在这里遗漏了一些非常明显的东西,但我是初学者所以请不要压垮我.我的问题是我有一个视口小于屏幕的舞台.现在我还想直接使用Sprite.draw(SpriteBatch)在屏幕上绘制一个Sprite.Sprite和舞台的位置不重叠.舞台绘制得很好,但Sprite不可见.当我在render-method中注释掉stage.draw()部分时,Sprite是可见的.

代码:这是我的渲染方法:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0.851f, 0.894f, 0.992f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();

    stage.act(delta);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    stage.draw();
    logoSprite.draw(batch);
    batch.end();
}
Run Code Online (Sandbox Code Playgroud)

在这里,我初始化相机和舞台(stageHeight是一个只有3/5*屏幕高度的int):

camera = new OrthographicCamera();
    camera.setToOrtho(false, SwapItGame.WIDTH, SwapItGame.HEIGHT);
    stage = new Stage();
    stage.setViewport(1080, stageHeight, true, 0, 0, 1080, stageHeight); //The button part of the menu takes up 3 fifth of the Height of hte screen
    stage.setCamera(camera);
Run Code Online (Sandbox Code Playgroud)

在这里我初始化我的Sprite(精灵的位置值相当复杂,只是忽略它.它肯定在舞台之上):

        logoSprite = skin.getSprite("logo");
        logoSprite.setPosition((SwapItGame.WIDTH-logoSprite.getWidth())/2, (SwapItGame.HEIGHT-stageHeight-logoSprite.getHeight())/2 + stageHeight);
Run Code Online (Sandbox Code Playgroud)

是不可能在同一个屏幕上有一个Sprite和一个舞台?还是我做了一些根本错误的事情?

小智 10

试着移动

stage.draw();
Run Code Online (Sandbox Code Playgroud)

以上批量操作

stage.draw();
batch.setProjectionMatrix(camera.combined);
batch.begin();
logoSprite.draw(batch);
batch.end();
Run Code Online (Sandbox Code Playgroud)

  • 是的,因为舞台有自己的批次!所以你需要结束你的批处理,因为你使用`stage.draw()`.此外,您还可以批量生产. (4认同)