LibGDX draw BitmapFont to intermediate location (spritebatch)

会有一股神秘感。 提交于 2019-12-24 14:05:10

问题


I want to draw some text using BitmapFont to some temporary location and then draw a portion of this location to the final spritebatch. I was thinking about drawing to a temporary spritebatch, but it's not possible to draw spritebatch onto another one. How could I accomplish this?


回答1:


Have you tried to write it into the pixmap temporarily? When you want to draw it, you can load the pixmap into texture object.

https://github.com/libgdx/libgdx/wiki/Pixmaps




回答2:


You could use a FrameBuffer. See my example below, you can draw whatever you want in the drawBuffer function and then draw it on the screen.

Hope this helps

--EDIT--

NOTE : you must have useGL20 = true; in your Application Configuration

public class SpaceMania extends Game  {
@Override
public void create() {
    setScreen(new ScreenView());
}

}

class ScreenView implements Screen{
    InputMultiplexer input;
    FrameBuffer buffer;

    SpriteBatch screenBatch;
    ShapeRenderer shape;

    @Override
    public void render(float delta) {
    //Draw Buffer
    drawBuffer();


    //Draw buffer to screen
    screenBatch.begin();
    screenBatch.draw(buffer.getColorBufferTexture(), 0,0,600,200);
    screenBatch.end();
    }

    public void drawBuffer(){
    buffer.begin();
    shape.begin(ShapeType.FilledCircle);
    shape.setColor(Color.RED);
    shape.filledCircle(50, 50, 50);
    shape.end();
    buffer.end();
    }
    @Override
    public void show() {
    buffer = new FrameBuffer(Format.RGBA8888, 200, 200,false);
    screenBatch = new SpriteBatch();
    shape = new ShapeRenderer();
    }

    @Override
    public void hide() {
    // TODO Auto-generated method stub

    }

    @Override
    public void resize(int width, int height) {
    // TODO Auto-generated method stub

    }

    @Override
    public void pause() {
    // TODO Auto-generated method stub

    }

    @Override
    public void resume() {
    // TODO Auto-generated method stub

    }

    @Override
    public void dispose() {
    // TODO Auto-generated method stub

    }
}


来源:https://stackoverflow.com/questions/20095957/libgdx-draw-bitmapfont-to-intermediate-location-spritebatch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!