Libgdx在纹理中保存SpriteBatch [英] Libgdx save SpriteBatch in a texture
问题描述
我想知道是否可以在纹理中保存spriteBatch 。
SpriteBatch batch = new SpriteBatch();
在批量内容中抽取一些东西后,我想在一个纹理中保存包含SpriteBatch的所有东西(类似于截图)。
我不知道该怎么做,我在网上和libgdx文档上搜索但没找到。
I have no idea to how to do it, I searched on the web and on the libgdx doc but didn't found.
谢谢你
推荐答案
您可以渲染到 FrameBufferObject
(FBO)。请参阅 https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects
You can render to a FrameBufferObject
(FBO). See https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects
如果您可以提前决定渲染纹理,FBO将会正常工作。一个副作用是图像不会渲染到屏幕,而只会渲染到纹理。 (当然,它很容易在屏幕上渲染纹理)。
An FBO will work if you are okay with making the decision to render to a texture in advance. 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).
正如另一个答案建议的那样,你可以从屏幕缓冲区中删除字节,然后制作结果 Pixmap
中的 Texture
(您不需要一直到文件系统)。请参阅 https://code.google.com/p/libgdx-users/wiki/截图(只需使用 getScreenshot
方法获取字节的 Pixmap
。
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). See https://code.google.com/p/libgdx-users/wiki/Screenshots (just use the getScreenshot
method to get a Pixmap
of the bytes).
这篇关于Libgdx在纹理中保存SpriteBatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!