How to put to sleep/remove the non-visible part of your map? (

42 views
Skip to first unread message

Pablo Suárez

unread,
Mar 28, 2016, 4:59:11 PM3/28/16
to Nape Physics

I'm creating a level modifying slightly the destructible terrain class from here:

http://napephys.com/samples.html#swf-DestructibleTerrain

Instead of using PerlinNoise to create a random map, I input my own bitmapdata. When the size of the terrain is the size of the stage, the performance is just fine, however when I put there a 4096x4096 custom bitmap, I get less than 25 fps, which is expected since it has a lot more of area to calculate.

What I tried so far that (partially) worked out , is passing a AABB region of the space that shouldn't count towards calculation, in other words what you don't see in the screen, and using something like this:

public function sleepBodies(origX:int, origY:int, width:int, height:int):void {
 
   var region:AABB = new AABB(origX, origY, width, height);
   var bl:BodyList = _space.bodiesInAABB(region);
   bl.foreach(putToSleep);
 
}
 
private function putToSleep(body:Body):void {
 
   _space.bodies.remove(body);
 
}

^ that works, and then when I want them to activate again I do something like:

_space.bodies.add(body);

For that I need to keep track of the bodies I'm removing their spaces that is.

However I'm unsure this is the best approach, and since I never ran into this issue before that I remember, not sure if it's a good idea.

Any advice is very welcome!.

T1m_

unread,
May 11, 2016, 6:50:24 AM5/11/16
to Nape Physics
It seems there is no better way. You could also pre-devide your world by cells (predefined AABB zones), determine which of them is closest to the camera (3 or 9 zones ) and use these AABB as you do right now. But if your approach works fine - leave it as is!
Reply all
Reply to author
Forward
0 new messages