简体   繁体   English

Libgdx在纹理中保存SpriteBatch

[英]Libgdx save SpriteBatch in a texture

I would like to know if it possible to save a spriteBatch in a texture . 我想知道是否可以在纹理中保存spriteBatch

 SpriteBatch batch = new SpriteBatch();

After drawing a few thing inside the batch , I would like to save all thing that contains the SpriteBatch in One texture (something like a screenshot ). 在批处理中绘制一些东西之后 ,我想在One纹理中保存包含SpriteBatch的所有东西 (类似于截图 )。

I have no idea to how to do it, I searched on the web and on the libgdx doc but didn't found. 我不知道怎么做,我在网上和libgdx文档上搜索但没找到。

Thanks you 谢谢

You can render to a FrameBufferObject (FBO). 您可以渲染到FrameBufferObject (FBO)。 See https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects 请参阅https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects

An FBO will work if you are okay with making the decision to render to a texture in advance. 如果您可以提前决定渲染纹理,那么FBO将会起作用。 One side-effect is that the image is not rendered to the screen, but only to the texture. 一个副作用是图像不会渲染到屏幕,而只会渲染到纹理。 (Its easy enough to render the texture to the screen afterwards, of course). (当然,它很容易将纹理渲染到屏幕上)。

As the other answer suggested, you can scrape the bytes off the screen buffer, and make a Texture from the resulting Pixmap (you do not need to go all the way to the filesystem). 正如另一个答案建议的那样,你可以从屏幕缓冲区中删除字节,并从生成的Pixmap创建一个Texture (你不需要一直到文件系统)。 See https://code.google.com/p/libgdx-users/wiki/Screenshots (just use the getScreenshot method to get a Pixmap of the bytes). 请参阅https://code.google.com/p/libgdx-users/wiki/Screenshots (只需使用getScreenshot方法获取字节的Pixmap )。

Use the conversion to texture like this: 像这样使用转换到纹理:

final Pixmap pmap = new Pixmap(bytes, 0, bytes.length);
try{
    Gdx.app.postRunnable(new Runnable(){
        public void run(){
        texture=new Texture(pmap);
        }
    });
}catch(Exception e){
    e.printStackTrace();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM