简体   繁体   中英

Andengine - a good rube loader?

I took a look on those 2 project that I found in here: 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.

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

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)
  • E2 is active and visible (currently displayed)
  • E3 is active but not visible yet
  • 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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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