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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:20:45+00:00 2026-06-09T17:20:45+00:00

I have a android game where I have to from time to time move

  • 0

I have a android game where I have to from time to time move camera (visible screen part) from point A to point B.

Obviously I could do it like that:

camera.setCenter(B.getX(), B.getY();

But it does not looks good, it simply jump immediately, and what I want to achieve is smooth movement from A to B. I can access onUpdate method which is loop updating certain game objects (so I can execute certain things in certain milliseconds)

I really can not figure out how to create such algorithm, to allow smooth movement between two points (Classifying I have no clue how to calculate what values should I add to the

camera.setCenter(camera.getX() + xValue, camera.getY() + yValue)

Because those values have to be calculated depends on what is distance between those two points.

  • 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-09T17:20:46+00:00Added an answer on June 9, 2026 at 5:20 pm

    If your game updates at 60 frames per second, and you want a transition to take two seconds, then it should take 120 frames to get there.

    Thus, the amount it should move in any given update is total/120.

    You can abstract this into a method that queues a movement, calculates the FPS and the amount to move each update, and calls .setCenter on its current position plus the update amount. This is typically called interpolation. To determine how far you need to move, its no more than the absolute value of current - destination (it doesn’t matter which is in front of the other, so we just take the absolute value to ignore the sign. To be technical, distance is a scalar whereas position is a vector).

    So, to sum up in semi-code (I don’t know the actual contracts for these functions):

    //given these variables already have value
    double fps, currentX, destinationX, currentY, destinationY, animationLength; //animation length in seconds
    ...
    double xValue = Math.abs(currentX - destinationX);
    double yValue = Math.abs(currentY - destinationY);
    ...
    //on each update:
    double amountToMoveX = xValue / (animationLength * fps);
    double amountToMoveY = yValue / (animationLength * fps);
    camera.setCenter(camera.getX() + amountToMoveX, camera.getY() + amountToMoveY)
    

    Then you simply need to keep track of when to stop, and you should be good to go.

    Whether or not you’re using an engine that already has a means of doing this, I don’t know. But in terms of a pure algorithm, this seems the way to go.

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

Sidebar

Related Questions

I have an Android game that includes a screen that lists all ongoing games,
I am making an android game that should display a message that you have
I have just started to develop a 2D Android game, something like squash a
As a natural part of writing a real-time game for Android, I'll need to
I would like to develop a game on Android platform, I have about a
Ok, I have my android game running smooth but can't get it to advance
I'm building a little Android game using libgdx. For now I have a copy
I'm working on an android game with OpenGL, and I have a game update
I'm creating an Android game and I encountered a problem. I have 2 threads:
I have been developing a game basic card game for Android. At the moment

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.