简体   繁体   English

Andengine-一个好的红宝石装载机?

[英]Andengine - a good rube loader?

I took a look on those 2 project that I found in here: AndEngineJb2dJson AndEngineRubeLoaderExtension 我看了一下在这里找到的那​​两个项目:AndEngineJb2dJson AndEngineRubeLoaderExtension

As some of you know I'm developing a rolling scene based game I'm loading all the entities from a XML file and create them in the Loading Scene recently I increase the game width , and by doing so , in the whole level I have about 500 entities (instead of 250+-) But this cause a performance problems , the game is "Lagging" \\ "jumping" and everything move slow. 如你们中某些人所知,我正在开发基于滚动场景的游戏,我正在从XML文件加载所有实体,并在最近的“加载场景”中创建它们,因此我增加了游戏宽度,并在整个级别上大约500个实体(而不是250 +-),但这会导致性能问题,游戏处于“滞后” \\“跳跃”状态,并且一切运行缓慢。

My question is , if those Rube Loaders support performance issues , do some improvement or its just like the normal andengine loader , that I need to manually load each entity in the XML \\ JSON 我的问题是,如果这些Rube Loader支持性能问题,请像常规andengine loader一样进行一些改进,或者它需要手动将XML \\ JSON中的每个实体加载

Does anyone develop a rolling scene based game with the same amount +- of entities and tell me what it the correct way to implement it? 是否有人开发具有相同数量实体的基于滚动场景的游戏,并告诉我实现它的正确方法是什么?

Thanks 谢谢

As you don't really provide much detail about your specific implementation I will just provide you with a generic way of handling a game of this type. 由于您实际上并未提供有关特定实现的详细信息,因此我仅向您提供一种处理此类游戏的通用方法。

First, you need to define an "active" area for your game world - this would be the area of the world that needs to be simulated (ie the entities in this area will move and interact with the world). 首先,您需要为游戏世界定义一个“活动”区域-这将是需要模拟的世界区域(即,该区域中的实体将移动并与世界互动)。

Your world layout might look something like this: 您的世界布局可能看起来像这样:

范例世界

In this example your world is the grey block and extends beyond the screen boundaries (which is the black frame). 在此示例中,您的世界是灰色块,并且超出了屏幕边界(即黑框 )。 The red frame indicates the active area - notice that it extends beyond the size of the display, but does not cover the entire world. 红色框表示活动区域-请注意,它超出了显示屏的大小,但并不覆盖整个世界。 The size of this area will depend on your specific implementation/needs. 该区域的大小将取决于您的特定实施/需求。

The active area will generally move along with your player and hence can easily be represented as distance from player (in two directions). 活动区域通常会随玩家一起移动,因此可以轻松地表示为与玩家的距离(在两个方向上)。

The basic idea is that the entities (in blue ) are only simulated while they are inside the active area. 基本思想是,仅当实体(以蓝色显示 )处于活动区域内时才对其进行仿真。 All entities to the right of the active area should be inactive until they enter it, at which point their simulation can start - for this reason, the active area should extend some amount to the right of the display area so that entities have some initial time to run their simulation before being displayed. 处于活动区域右侧的所有实体在进入它们之前都应该处于非活动状态,此时可以开始进行模拟-出于这个原因,活动区域应向显示区域右侧扩展一定数量,以便实体具有一些初始时间在显示之前运行其模拟。 Once the entities leave the active area (to the left) they can stop their simulation - and be removed if needed. 一旦实体离开活动区域(向左),它们就可以停止其模拟-如果需要,可以将其删除。

So in the example image: 因此,在示例图片中:

  • E1 is has already gone through the active area and is no longer needed (it can be disabled/removed) E1已经通过活动区域,不再需要(可以将其禁用/删除)
  • E2 is active and visible (currently displayed) E2处于活动状态并且可见(当前显示)
  • E3 is active but not visible yet E3处于活动状态但尚不可见
  • E4 and E5 is not active yet and will only become active once they enter the active area as the player gets closer to them E4E5尚未激活,并且仅在玩家靠近它们进入活动区域后才会变为活动状态

As for how to handle the entities, that depends on the size of the world, the number of entities, etc. 至于如何处理实体,这取决于世界的大小,实体的数量等。

One way is to create/load the entities once they enter the active area - in which case it should extend far enough to the right of the display so that they have enough time to be created/loaded before entering the display area. 一种方法是在实体进入活动区域后创建/加载它们-在这种情况下,实体应延伸到显示右侧足够远的位置,以便它们在进入显示区域之前有足够的时间来创建/加载。 This is the best approach for large worlds where there may be thousands of entities. 对于可能有成千上万个实体的大世界,这是最好的方法。 In this case you may also need some kind of subdivision for your world so that you can exclude large amounts of entities from processing without checking each one - a array of fixed sized "blocks", each containing the entities that are within it, would work fine in most cases for a simple 2D side-scroller. 在这种情况下,您可能还需要对您的世界进行某种细分,以便可以在不检查每个实体的情况下排除大量实体,而无需检查每个实体-固定大小的“块”阵列(每个包含其中的实体)将起作用在大多数情况下,对于一个简单的2D侧滚动条来说,效果很好。

Another approach is to load all objects at the start and only perform simulation updates (such as physics, movement, collision detection) for them once they enter the active area. 另一种方法是在开始时加载所有对象,并在它们进入活动区域后才对其执行仿真更新(例如物理,运动,碰撞检测)。 This approach works great for smaller worlds and provides an easier implementation. 这种方法适用于较小的领域,并提供了更容易的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM