LibGDX将BitmapFont绘制到中间位置(spritebatch) [英] LibGDX draw BitmapFont to intermediate location (spritebatch)
问题描述
我想使用BitmapFont绘制一些文本 临时位置,然后画出该位置的一部分 到最后的spritebatch.我在想画画 到一个临时的spritebatch,但是不可能 将spritebatch绘制到另一个.我该怎么办?
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?
推荐答案
您可以使用FrameBuffer.参见下面的示例,您可以在drawBuffer函数中绘制所需的任何内容,然后在屏幕上绘制它.
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.
希望这会有所帮助
-编辑-
注意:您必须具有useGL20 = true;在您的应用程序配置中
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
}
}
这篇关于LibGDX将BitmapFont绘制到中间位置(spritebatch)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!