Putting off screen RigidBodies to sleep

1 view
Skip to first unread message


Mar 2, 2009, 5:24:50 AM3/2/09
to glaze Engine
I'm tinkering with a parallax scrolling game engine using glaze and I
needed RigidBodies to sleep when they go off the screen.

I copied the Space.cullOutOfBounds() function to make sleepOutOfBounds

In the Space class:

public virtual function execIntervalFunctions():void {
//if ( frame % 100 == 0 ) cullOutOfBounds();
if ( frame % 40 == 0 ) sleepOutOfBounds();
if ( frame % 30 == 0 ) sleepBodys();

public function sleepOutOfBounds():void {
var body:RigidBody = activeBodies;
var shape:GeometricShape;

var numShapes:int;
var snooze:Boolean;
while (body) {
snooze = true;
numShapes = body.memberShapes.length;
for (var j:int = 0; j < numShapes; j++) {
shape = body.memberShapes[j];
if (!(worldBoundary.l > shape.aabb.r || worldBoundary.r <
shape.aabb.l || worldBoundary.t > shape.aabb.b || worldBoundary.b <
shape.aabb.t)) {
snooze = false;
if (snooze) {
var nextBody:RigidBody = body.next;
body = nextBody;
} else {
body = body.next;

I then set up a Event.ENTER_FRAME listener in my game class to make
the space.worldBoundry AABB object follow the camera every couple
frames or so.

1. Is this the best way to go about this? It works but I notice that
now, on-screen objects don't go to sleep unless I set the interval for
sleepOutOfBounds() for a very long a time. I don't plan on having too
many awake RigidBodies on the screen at once.

2. What other pitfalls might be in store for me if I want large,
scrolling levels with lots of static RigidBodies? Will I need to write
another function to put static bodies to sleep as they move off screen?
Reply all
Reply to author
0 new messages