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:
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!.