Question

I have a problem with my code, which appeared after i started using steps to draw my UI, I have 3 things being drawn with Batch, and a stage with 2 buttons being drawn by Stage, but only 2 of my "Sprites" are being drawn. Here is the code:

public void render(float delta) {
    Gdx.gl.glClearColor(0.95F, 0.95F, 0.95F, 0.95F);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    deltaTime = Gdx.graphics.getDeltaTime();

    camera.update();
    generalUpdate(touch, camera, deltaTime, pointer);
    bounce(deltaTime);

    stage.setCamera(camera);
    batch.setProjectionMatrix(camera.combined);

    batch.begin();
        batch.draw(Assets.spr_bg, 0, 0);
        batch.draw(Assets.spr_title, 540-Assets.spr_title.getWidth()/2, titleY-Assets.spr_title.getHeight()/2);
        Assets.font_small.draw(batch, "some text", 540-Assets.font_small.getBounds("(c)2014 HateStone Games").width/2, 1920-64-Assets.font_small.getBounds("(c) HateStone Games").height/2);
        stage.draw();
    batch.end();
}

It is the text "Some text" which doesn't get drawn, and if i comment it out, it goes crazy, the title sprite doesn't get drawn either, and a gray box appears at random intervals.

Also if I move "stage.draw();" outside of the batch it doesn't get drawn

Était-ce utile?

La solution

The Stage has its own SpriteBatch, which draws everything. So you begin() a SpriteBatch while your other SpriteBatch is drawing. So call batch.end() before calling stage.draw(). This should solve your problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top