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?
Have you tried to write it into the pixmap temporarily? When you want to draw it, you can load the pixmap into texture object.
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.