Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Libgdx在纹理中保存SpriteBatch_Java_Textures_Libgdx_Spritebatch - Fatal编程技术网

Java Libgdx在纹理中保存SpriteBatch

Java Libgdx在纹理中保存SpriteBatch,java,textures,libgdx,spritebatch,Java,Textures,Libgdx,Spritebatch,我想知道是否可以将spriteBatch保存在纹理中 SpriteBatch batch = new SpriteBatch(); 在批处理中绘制了一些内容后,我想将包含SpriteBatch的所有内容保存在一个纹理中(类似于屏幕截图) 我不知道怎么做,我在网上和libgdx文档上搜索过,但没有找到 谢谢您像这样使用纹理转换: final Pixmap pmap = new Pixmap(bytes, 0, bytes.length); try{ Gdx.app.postRunnab

我想知道是否可以将spriteBatch保存在纹理中

 SpriteBatch batch = new SpriteBatch();
在批处理中绘制了一些内容后,我想将包含SpriteBatch的所有内容保存在一个纹理中(类似于屏幕截图

我不知道怎么做,我在网上和libgdx文档上搜索过,但没有找到


谢谢您

像这样使用纹理转换:

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();
}

您可以渲染到
FrameBufferObject
(FBO)。看

如果您可以提前决定渲染到纹理,则FBO将起作用。一个副作用是,图像不会渲染到屏幕,而只渲染到纹理。(当然,之后将纹理渲染到屏幕上非常容易)


正如另一个答案所建议的,您可以从屏幕缓冲区中刮取字节,并从生成的
Pixmap
中生成
Texture
(您不需要一直到文件系统)。请参阅(只需使用
getScreenshot
方法获取字节的
Pixmap

如果只是为了拍摄屏幕快照,请使用此方法。我知道这个代码,但它不好有两个原因:1。您必须将屏幕截图保存在文件中。2.在文件中保存并在纹理中加载文件会太长,在执行过程中会浪费很多时间。请记住,我希望将此屏幕截图保存在Textureuse texture=new texture(pixmap)中,而不是保存到文件我在0x673b3000(代码=1)处得到致命信号11(SIGSEGV),线程5116(线程-19425)使用下面的代码转换为纹理