Performance with Box2D
Monkey Targets Forums/Android/Performance with Box2D| 
 | ||
| Hello, I was wondering if anyone has made a game for android using  monkey-box2D. I've been doing some tests on a Samsung Galaxy S2 and it runs very choppy. Sometimes the FPS goes from 60 to 20 and then it stays at 25-35 for a while. I am running this test which runs good on my pc(html5, flash and glfw): http://shin.cl/b2d/ , but on android it just runs very very slow. What have your performance tests been like with box2d on android, and what do you recomend to improve speed. Thanks! | 
| 
 | ||
| You need to run a profile to see where the time is going. I don't see 30fps as "very slow" to be honest but equally your example doesn't look much of a physics processing strain for a reasonably powerful device. Profiling your HTML5 build did point out something a little odd: 13% of the processing time was going to SetPosition. That seems to come from this bit of your update: var t_=bb_main_world.f_entities.m_ObjectEnumerator(); while(t_.m_HasNext()){ var t_e=t_.m_NextObject(); var t_pos=t_e.f_body.m_GetPosition(); t_pos.f_x=t_pos.f_x-this.f_offset.f_x; t_pos.f_y=t_pos.f_y-this.f_offset.f_y; t_e.f_body.m_SetPosition(t_pos); } Are you repositioning every object in the world on every update? | 
| 
 | ||
| Yes I am, i am doing this to give the camera effect. If there is a better way for this could you point me how or where to find a reference?? This is my first time working with box2D. Thanks | 
| 
 | ||
| Just have a camera object and offset the rendering rather than moving objects in the world. Every time you move an object in box2d it has to recalculate a bunch of stuff to do with collisions etc. | 
| 
 | ||
| Ooh, yeah that sounds a lot smarter, I'm actually not handling the render, I am using CopperCircle's box2dframework so I'll have to "hack it". I'll see  how it works after doing all this. Thanks | 
| 
 | ||
| You can probably just use mojo's translate matrix function to shift everything to centre on the player before you call the render loop. | 
| 
 | ||
| Thanks  a lot, that was really a preformance boost. Now the demo runs at 60fps on all targets. Thanks! | 
| 
 | ||
| Hi do you have an example of the translate matrix scrolling? did you get it to work with my framework? | 
| 
 | ||
| +1 |