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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:17:25+00:00 2026-06-18T12:17:25+00:00

I’m trying to create an animation like a hockey disc moving slowly and whose

  • 0

I’m trying to create an animation like a hockey disc moving slowly and whose speed decreases little by little.

So I tried to do this :

for(Disc d : panel.getDiscs()
{
    if(d.getLaunch() <= 70) move(d);
}

And :

private void move(Disc d)
{
        Point p = d.getLocation();
        Point speed = d.getSpeed();
        Dimension size = d.getSize();

        int vx = speed.x;
        int vy = speed.y;

        int x = p.x;
        int y = p.y;

        if (x + vx < 0 || x + size.width + vx > panel.getWidth()) {
            vx *= -1;
        }
        if (y + vy < 0 || y + size.height + vy > panel.getHeight()) {
            vy *= -1;
        }
        x += vx;
        y += vy;

        d.setSpeed(new Point(vx, vy));
        d.setLocation(new Point(x, y));

    try
    {
        Thread.sleep(d.getLaunch());
    } catch (InterruptedException e)
    {
        e.printStackTrace();
    }
        if(d.getCoeff() < 5) d.setCoeff(d.getCoeff()+1);
        else { d.setLaunch(d.getLaunch()+1); d.setCoeff(0); }
}

What I’m trying to do here is to increase a value (launch) that begins at 20 and keeps running until 70, then I use this value in every Thread.sleep(launch);.
I only increase this value when 5 frames were previously displayed (coeff).

The problem is the following : when I try it with a too small value, the disc is too fast and stops running too early. When I try it with a higher value, the disc speed looks well but the last animations are not very smooth… What should I do ?

  • 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-18T12:17:26+00:00Added an answer on June 18, 2026 at 12:17 pm

    Your approach seems invalid. Displaying the disc and determining it’s position are two different things. I think that:

    • in one thread you should periodically (100 times a second?) calculate the position of the disc
    • several times per second you should decrease the speed of the disc (base this speed decrease on System.currentTimeMIlliseconds(), not on how many times the loop was executed)
    • 30-60 times per second draw the position of the disc
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.