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

  • SEARCH
  • Home
  • 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 3455016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:33:44+00:00 2026-05-18T09:33:44+00:00

I draw a lot of lines rectangles each frame in my game – it’s

  • 0

I draw a lot of lines rectangles each frame in my game – it’s a recreation of an old school handheld electronic game. The ones that had crude dot matrix display for the main game and custom images for text or some images.

I have 20×20 big “pixels” on a virtual dot matrix screen, I also draw some 7-segment displays on the screen and some other things.

According to TraceView, most of time is spent at drawLine and drawRectangle methods, because there is simply too much of them. I draw each ‘pixel’ of the dot matrix display, and each segment of 7-segment displays in every frame.

An optimization came to my mind, that I would repaint only those pixels/segments which changed, so I have saved the previous state of pixels/segments and tried to repaint only changed ones. Basically it’s a crude invalidation.

The behavior I was expecting was that the Canvas would stay as it was after the last frame finished painting, and I would only repaint necessary stuff.

Alas, my Canvas was flickering to black and every once in a while when state of my screen changed, only pixels of dot matrix display/segments flickered on for a frame. And I made sure that I didn’t Clear my canvas.

I’m drawing on a Canvas inside a SurfaceView, updating Thread, as is described in Lunar Lander Android sample. In the Lunar Lander sample, they repaint everything in each frame.

Maybe I could render everything to a Bitmap on the first frame, then update that Bitmap on every other frame?

Which technique should I use for my paint() method?

  • 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-05-18T09:33:44+00:00Added an answer on May 18, 2026 at 9:33 am

    SurfaceHolder.unlockCanvasAndPost() actually does page flipping on the Surface, so even if the previous frame wasn’t cleared out you’d get the 2nd oldest frame, not the one you just drew. and doing lock() on a surface instantiates a new canvas each time which probably is doing the clearing in its constructor.

    You’re better off drawing into a Bitmap like someone suggested and then drawBitmap on the canvas each time you want to present the image to the display. You can aquire a canvas from a bitmap to draw into it

    and like someone else suggested (very ambiguously), you can generate sprites for the dot matrix display and draw those directly from a cache of bitmaps rather then draw with primitive commands. ie for a dot matrix calculator you could generate all 0-9 into 10 bitmaps and simply blit them on the canvas rather then calling a set of drawLine/Rect operations.

    if the above are still too slow there still is opengl, which takes advantage of hardware acceleration

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

Sidebar

Related Questions

I need to draw a lot of lines. I'm using UIBezierPath for drawing lines
I need to draw a lot of (about 500000) little lines in some area
I have an angle in a frame (I draw it with two lines). I
I want to draw a lot of lines on JPanel in a short time
when i draw a lot of lines, the apps takes a long time to
I'm trying to draw a lot of similar kind of lines in WPF as
I'm making my first game using Java on Android. I need to draw a
I am trying to draw a rectangle with 4 lines (left one). But no
I'm trying to draw a chart with a single datapoint each month. I'm sending
//Draw Icon for (var i = 0; i < diagram.Children.length; i++) { if (diagram.Children[i].Icon

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.