views:

329

answers:

2

I've created a small game with Box2d for AS3 - I have sprites attached to the stage that take their position from the underlying Box2d world. These sprites are mostly PNGs.

When the game runs with DrawDebugData() bening called every update, it runs nice and smoothly. However when I comment this out, it runs choppily. In both cases all my sprites are being rendered. So it seems that it's running faster when it's drawing the debug data additionaly (i.e. my sprites are on the screen in both cases!)

What's going on? Does drawing the debug data flick some sort of 'render quick' switch? If so, what's the switch!? I can't see it in the Box2D code.

function Update(e){
    m_world.Step(m_timeStep, m_velocityIterations, m_positionIterations);
    // draw debug?
    m_world.DrawDebugData();
    // with the above line in, I get 27fps, without it, I get 19fps.
    // that's the only change that's causing such a huge difference.
    doStuff();
}

Interestingly, If i set the debug draw scale to something different to my world scale, it slows down to 19fps. So there's something happening when it draws the boxes under my sprites causing it to run quicker..

Cheers,

Guy

A: 
private var gravity:b2Vec2 = new b2Vec2(0, 7.8);
private var doSleep:Boolean = false;
private var iterations:int = 10;
private var timeStep:Number = 1/30;

can your share this settings with us? doSleep improves the performance a lot

antpaw
The thing is, I'm getting 27fps with the debug data drawing, and 19 without. I'm just commenting out this line in my EnterFrame function:m_world.DrawDebugData();
Guy Bowden
A: 

I had the same problems when testing box2d last year. I set the alphafill and outline alpha to 0 of the debug draw :D or you can remove flags so it doesn't debug joints etc.

it's just a work around. I'll look into box2d now. If I find out a solution to get same performance w/o debugdraw I tell you.

Im using box2d 2.1a btw.

martinlindelof