Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7931047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:36:30+00:00 2026-06-03T20:36:30+00:00

I’m playing around with drawing jbox2d objects onto a surfaceview, yet I’m not really

  • 0

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

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:36:32+00:00Added an answer on June 3, 2026 at 8:36 pm

    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:

    the problem with PNGs start when I have to rotate and scale them (
    when the user zooms in or out )

    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.

    Libgdx Box2D

    I don’t know how much of a performance gain there is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.