I’m playing around with drawing jbox2d objects onto a surfaceview, yet I’m not really satisfied with the framerate I’m getting ( 10-13, when there are multiple objects on screen / in debug more I’m getting about 26-30 ).
while (isRun)
{
Canvas canvas = holder.lockCanvas();
_update(canvas); /// <- call to update
holder.unlockCanvasAndPost(canvas);
}
…
canvas.drawColor(0xFF6699FF);
for ( Body b = world.getBodyList(); b!=null; b = b.getNext() ) // <- cycle through all the world bodies
{
rlBodyImage bi = new rlBodyImage();
bi = (rlBodyImage) b.getUserData();
float x = b.getPosition().x*scale + wOffset + camera_x + camera_x_temp;
float y = b.getPosition().y*-scale + hOffset + camera_y + camera_y_temp;
canvas.save();
canvas.translate( x - (bi.getImage().getWidth()*bi.getCoof()*scale)/2 , y - (bi.getImage().getHeight()*bi.getCoof()*scale)/2 );
canvas.scale( bi.getCoof()*scale , bi.getCoof()*scale );
canvas.rotate( (float) -(b.getAngle() * (180/Math.PI)) , bi.getImage().getWidth() /2 , bi.getImage().getHeight() /2 );
canvas.drawPicture(bi.getImage()); // <- draw the image assossiated with current body on canvas
canvas.restore(); // images are stroed as "Pictures" , extracted from SVGs.
}
Is there a way to speed things up, other then of course using more simple SVGs? 🙂
Thanks!
EDIT :
Yep, will have to switch to PNGs, they give way better FPS rate.
vector Pictures = 10…13…16 FPS
PNG only = 35…40+ FPS
PNG with scaling = 32…37+ FPS
PNG with scaling & rotation = 27+ FPS

You should probably use a rasterized image instead of SVGs. You can either save them to pngs or similar before/during compile, or the phone can convert them to fitting images on (first) startup.
And it seems like you are swapping texture to be drawn multiple times per frame. That is extremely expensive for the GPU. You should create one big sprite/imageatlas containing all your images, load it onto the GPU and then draw different regions of it to the screen.
And do not allocate many new objects each frame if you are not going to use them for a longer time. The GC will freeze your game for a short period of time every now and then, dropping your fps.
Edit: you should also achieve much more than ~20 fps in debug mode (unless your phone is really old). Consider optimizing your box2d world. You should maybe consider using the Libgdx framework. It provides a JNI wrapper for Box2d, greatly improving performance.
Edit2:
This is not an issue. Save the PNGs as the maximum size they will be shown on screen, and then just scale and rotate them to fit. If you use proper minification filter, and maybe add some extra space around (see this post for an example), you should see no to minimal loss in quality. If needed, you can create one large version and a smaller version of each sprite, and draw the one fitting best. Or just use mipmapping in OpenGL. And there is no way you should need to save a version for every size/angle of each sprite.
I don’t know how much of a performance gain there is.