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 8754757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:42:04+00:00 2026-06-13T13:42:04+00:00

I am making a board game. The board doesn’t ever move, but pieces on

  • 0

I am making a board game. The board doesn’t ever move, but pieces on top of it sometimes do depending on user interaction. There are also UI elements which may update periodically.

Right now the way I set it up is by overwriting the onDraw() method of a SurfaceView subclass. I have a drawing thread that constantly calls postInvalidate() in a while loop:

class PanelThread extends Thread
{
        //...
    long sleepTime = 0;
    long nextGameTick = System.currentTimeMillis();

    @Override
    public void run()
    {
        Canvas c;
        while (_run)
        { // When setRunning(false) occurs, _run is
            c = null; // set to false and loop ends, stopping thread
            try
            {
                c = _surfaceHolder.lockCanvas(null);
                synchronized (_surfaceHolder)
                {
                    // Insert methods to modify positions of items in onDraw()
                    _panel.postInvalidate();
                }
            } finally
            {
                if (c != null)
                {
                    _surfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
            nextGameTick += MILLISECONDS_PER_FRAME;
        sleepTime = nextGameTick - System.currentTimeMillis();
        if(sleepTime >= 0)
        {
            try
            {
                sleep(sleepTime, 0);
            } catch (InterruptedException e)
            {
                continue;
            }
        }
        else
        {
            //we're behind, oh well.
            System.out.println("behind!");
            nextGameTick = System.currentTimeMillis();
        }
    }
}

This is not efficient and is taking a lot of CPU. Is there a easy way to get android to only update when something changes?

  • 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-13T13:42:05+00:00Added an answer on June 13, 2026 at 1:42 pm

    You have the right idea, but it needs a bit of refinement.

    You definitely do not want to loop as fast as the CPU can handle it though.
    You should be sleeping your Thread in every loop for a little while. You most certainly do not need to do everything in your loop every millisecond.

    I found this guide to FPS control to be incredible helpful in designing a game loop.

    This Android-specific game loop guide also provides a lot of great sample code and an in-depth explanation.

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

Sidebar

Related Questions

I am making a board game and having trouble moving them. The piece will
So lets say i'm making a board game. i've got a game board array,
I'm making a game. In the game there is a grid that is populated
I'm making a game where the user plays against the computer. The computer opponent
I'm working on making a board game for chess and checkers (and a few
I'm just getting started on making a board game using Cocoa/Objective-C. My plan is
I'm making Pacman game in opengl and I want to move my pacman in
I'm making a Tic-tac-toe game and i have a board class which contains 9
I'm in the process of making a board game in Flash; as part of
I'm making a game with Python->PyGame->Albow and ran into a problem with board generation.

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.