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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:33:21+00:00 2026-05-26T06:33:21+00:00

I have an image which moves horizontally with a given speed over a delta

  • 0

I have an image which moves horizontally with a given speed over a delta time(dt). But the problem is,the image doesn’t bounces off when it reaches the end of the size of the world.How can i make the image bounces off backward so it would be kept inside the world?

Any help will do.

Here’s what i’ve tried so far:

@Override
public void move(long dt)
{
    // v = dx / dt
    //   dx m = v m/s  . dt s

    double dt_s = dt / 1e9;
    double dx_m = speed * dt_s;


    double left_wall = 0;
    double right_wall = board.x1_world;

    if (x <= right_wall)
    {
        x += dx_m;
        if (x >= right_wall)
        {

            x = right_wall;
           x *= -dx_m;
        }
    }
}
  • 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-26T06:33:21+00:00Added an answer on May 26, 2026 at 6:33 am
        @Override
    public void move(long dt)
    {
        double dt_s = dt / 1e9;
        double dx_m = speed * dt_s;
    
    
        double left_wall = 0;
        double right_wall = board.x1_world;
    
        x += dx_m;
        if (x <= 0) speed *= -1.0;
        if (x >= right_wall) speed *= -1.0;
    }
    

    When the x coordinate of your images reach an border, just change the orientation of the horizontal speed (multiply it for -1). But you should use an condition like this:

    if (x >= (right_wall - width_of_image)) speed *= -1.0;
    

    Instead of just x >= right_wall, because doing so, the image will bounce when it “touchs” the end of the world.

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

Sidebar

Related Questions

I have an image which moves in a random direction. My problem is everytime
I have a view and template called index.html. I have a image which is
Hope someone has an easy answer on this. I have a header image which
I have an object of type IMAGE which holds image. I wanted to display
I have a small (100x80) overlay image which will be placed at x=40, y=50
How to do the following: I want to have a link [upload image] which
I have an image on my webpage in which I want to have text
I have an image uploader and cropper which creates thumbnails and I occasionally get
I have a binary image (a dll) which I wish to view the assembly
I have an image on a webpage which is being dynamically generated by a

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.