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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:03:23+00:00 2026-05-26T10:03:23+00:00

I’m writing a little game as part of a programming assignment. I’ve got my

  • 0

I’m writing a little game as part of a programming assignment. I’ve got my sprites/images moving the way I want to, except they’re very jerky. Here’s how I’m loading up the image:

//missile and paint are private members of the animation thread
missile = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.missile));
paint = new Paint();
paint.setAntiAlias(true);
startTime = new Date().getTime();

The run method of my thread is like this:

@Override
public void run() {
    while(running) {
        Canvas canvas = null;

        try {
            canvas = surfaceHolder.lockCanvas(null);

            synchronized (surfaceHolder) {
                updatePhysics();
                doDraw(canvas);
            }
        } finally {
            if(canvas != null) {
                surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }
    }
}

updatePhysics simply performs calculations and stores the value inside a private member of the thread called projectilePosition:

function updatePhysics() {
    projectilePosition = interceptionCalculationService.positionAtTime((startTime - new Date().getTime()) / 1000);
}

Then, in my doDraw method I do:

private void doDraw(Canvas canvas) {
    canvas.drawColor(Color.BLACK);

    ...

    //I update the position of the missile
    canvas.drawBitmap(missile, (int) projectilePosition.getDistance() * 2, (int) (getHeight() - (95 + projectilePosition.getHeight())), paint);
    canvas.restore();
}

The problem is that the animation is extremely jerky. The missile follows the correct path, but it’s not smooth at all. I assume that’s because I don’t really control the interval when the thread’s run method is called. How can I make my animation more smooth? I was looking at TranslateAnimation, but I can’t figure out how to use it.

This is my first time writing a game and doing graphics/animation, so I’m not well aware of the best practices or even the tools. I got this far by looking up numerous tutorials.

  • 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-26T10:03:23+00:00Added an answer on May 26, 2026 at 10:03 am

    My solution was to stop relying on the system time and to use a variable (that is a private member of the thread) called currentTime that gets incremented in either doDraw or updatePhysics. So updatePhysics becomes:

    function updatePhysics() {
        projectilePosition = interceptionCalculationService.positionAtTime(currentTime);
        currentTime++;
    }
    

    currentTime is initialized to 0 in the constructor of the thread. This made my animation smooth.

    • 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 want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
i got an object with contents of html markup in it, for example: string
I want to construct a data frame in an Rcpp function, but when I

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.