静态精灵批处理? [英] Static sprite batch?
问题描述
我的研究无处不在,据说我们每个实例只能使用一个精灵批.但是,如果我在控制游戏的类中将子画面批处理设置为静态(调用不同的屏幕等),该怎么办?
As my research goes everywhere it's said that we should only use one sprite batch per instance. But what if i set sprite batch to static in class which controls the game (calls different screens etc).
当我尝试过这种方法时,它的工作原理就像魅力一样,但这是一种好的做法,否则将来可能会导致一些问题.然后,如果可以的话,我还可以共享舞台和形状渲染器吗?
When i have tryed this its working like charm, but is that a good practice or it may result some problems in future. Then if it could be done can i also share stage and shape renderer?
注意:我尝试使用静态批处理技术"的主要原因是,当我尝试处理舞台,子画面批处理或形状渲染器时,java崩溃了
note: the main reason why i am trying to go with that "static batch technique" is that java crashes when i try to dispose stage, sprite batch or shape renderer
推荐答案
我也是这样做的,到目前为止我还没有遇到任何问题.
I do it that way as well and I didn't run into any problems so far.
您需要小心使用SpriteBatch.begin()
和SpriteBatch.end()
调用,因为您可能永远都不知道它在哪里开始,以及在共享时在哪里停止.
You need to be careful with the SpriteBatch.begin()
and SpriteBatch.end()
calls, since you may never know where it was started already, and where it was stopped when it is shared.
对于Camera
/ProjectionMatrix同样适用.并针对当前使用的ShaderProgram
(如果您正在使用着色器).
Same applies for the Camera
/ProjectionMatrix. And also for the currently used ShaderProgram
in case you are working with shaders.
请确保您始终完全了解SpriteBatch
在做什么,否则有一天您可能会遇到奇怪的错误.
Make sure that you are always fully aware of where you are doing what with your SpriteBatch
otherwise you might face weird bugs one day.
Stage
不应共享,因为它可能有不同的用途.对于不同的UI,仅使用一个Stage
没有任何意义.
Stage
should not be shared, since it will probably serve different purposes. For different UIs it doesn't make any sense to use only one Stage
.
ShapeRenderer
可以共享,因为它的工作方式类似于SpriteBatch
,但是您可能只想在一个地方使用它.
ShapeRenderer
could be shared, since it kind of works the same like SpriteBatch
, but probably you only want to use it in a single place.
dispose()
实际上应该没有任何问题.您必须确保以正确的顺序处理所有内容,以便最终不会遗留任何东西并引起异常.
dispose()
should actually work without any problems. You have to make sure that you dispose everything in the correct order so nothing will be left over in the end and cause exceptions.
这篇关于静态精灵批处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!