在大世界的游戏中正确使用scene2d的舞台 [英] Proper using of scene2d's Stage in a game with a huge world
问题描述
如果整个游戏世界"比视口宽数千倍,并且如果我想使用 scene2d 将游戏对象作为 Actor
进行管理,我应该创建与整个世界,或者 Stage
应该是当前视口周围的某个区域,而不是整个世界?
换句话说,具有更大宽度和高度的 Stage
本身是否会消耗更多内存,即使我只在其一小部分视口大小的部分上渲染对象?
If the whole "game world" is thousands of times wider than a viewport, and if I want to use scene2d to manage game objects as Actor
s, should I create Stage object as wide as the whole world, or should the Stage
be some area around current viewport but not the whole world?
In other words, does a Stage
with greater width and height consume more memory itself, even if I render objects only on a small viewport-sized part of it?
推荐答案
我想你误解了 Stage
到底是什么.舞台本身并没有真正的尺寸.您无需指定宽度或高度或 Stage
,您只需指定视口的宽度和高度.视口就像一个窗口,它只显示你世界的一部分,也就是场景.Stage
是一个 2D 场景图,它与您的 Actors
一起成长".您拥有的 Actor 越多,您的 Stage 就越大(在内存方面),但这并不取决于您的 Actor 的实际分布范围.如果它们分布得很远,而您只显示整个 Stage
的一小部分,它将被非常有效地处理,因为场景图细分了这个巨大的空间以便能够非常快速地决定是否忽略某个 Actor,或者在屏幕上绘制它.
I think you misunderstood what exactly a Stage
is. A Stage doesn't really have a size itself. You don't specify a width or height or the Stage
, you only specify the width and height of the viewport. The viewport is like a window, which shows only a part of your world, aka scene. A Stage
is a 2D scene graph and it "grows" with your Actors
. The more Actors you have, the bigger (memory wise) your Stage is, but it doesn't depend on how far spreaded your Actors actually are. If they are very far spreaded and you only display a very small part of your whole Stage
, it will be handled very efficient, because a scene graph sub-divides this huge space to be able to very quickly decide whether to ignore a certain Actor, or draw it on the Screen.
这意味着 Stage
实际上正是您在这种情况下所需要的,并且您应该不会有任何问题,FPS 和内存方面.但是当然,如果您的 Stage
是视口大小的 1000 倍,并且您自己知道某些 Actor 不会很快显示,那么不添加可能是有意义的他们还没有上台.
That means a Stage
is actually exactly what you need for this kind of situation and you should probably not have any problems, FPS and memory wise. But of course if your Stage
is 1000s of times the size of your viewport and you know yourself that certain Actors aren't displayed soon, then it might make sense to not add them to the Stage yet.
这篇关于在大世界的游戏中正确使用scene2d的舞台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!