在拥有巨大世界的游戏中正确使用Scene2d的舞台 [英] Proper using of scene2d's Stage in a game with a huge world

查看:52
本文介绍了在拥有巨大世界的游戏中正确使用Scene2d的舞台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果整个游戏世界"的宽度是视口宽度的数千倍,并且如果我想使用scene2d作为 Actor s管理游戏对象,那么我应该创建与整个世界,还是 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 Actors, 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越多,舞台就越大(在内存方面),但这并不取决于Actor的实际分布范围.如果它们分布得很远,而您只显示整个 Stage 的一小部分,它将得到非常有效的处理,因为场景图将这个巨大的空间细分了,以便能够快速确定是忽略某个演员还是将其绘制在屏幕上.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆