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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:23:00+00:00 2026-06-15T04:23:00+00:00

this is an algorithm/data structure question about making different animations at the same time.

  • 0

this is an algorithm/data structure question about making different animations at the same time. For example, a ball is falling down one pixel in a millisecond, a bullet is moving 5 pixels in a ms, and a man is moving 1 pixel in 20 milliseconds. And think that there are hundreds of them together. What is the best way of putting all animations together, moving what we need to move in one function call, and removing the ones whose animation is completed? I don’t want to create a thread for each one. What I want to do is to create one thread moving all items and sleeping until an object needs to be moved.

Note: I’m using Java/Swing, printing objects and images in JPanel.

  • 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-15T04:23:01+00:00Added an answer on June 15, 2026 at 4:23 am

    I recently did something similar in Python. I don’t know if this is the best method, but here’s what I did.

    Create an abstract Event class with the following public interface:

    • tick – calculates how much time has passed since the last tick. Perform work proportional to that time span. This should be called frequently to create the illusion of smooth movement; maybe sixteen times a second or so.
    • isDone – returns true when the Event has finished occuring.

    Make a subclass of Event for anything that takes more than one frame to finish. Rotating, scaling, color changing, etc. You might create a TweenEvent subclass of Event if you want to move an image from one part of the screen to another. During each tick, redraw the image in a position farther away from the original position, and farther towards the destination position.

    You can run many Events concurrently, like so:

    Array<Event> events = new Array<Event>();
    
    //add a bunch of TweenEvents here - one for a bullet, one for a ball, etc.
    
    while(True){
        Sleep(1/16);
        for(Event e in events){
            e.tick();
            if (e.isDone()){events.remove(e);}
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this formula from a data structure book in the bubble sort algorithm.
This question is more a semantic-algorithmic-data-structure question than a F# syntactically question. I have
My question can be asked in two different aspects: one is from data structure
This question is merely about algorithm. In pseudo code is like this: A =
I'm trying to implement this algorithm description from a previous question I had here
I'm trying to basically reverse this algorithm so that I get the time for
Consider this sequential procedure on a data structure containing collections (for simplicity, call them
Got a question regarding to the underlying data structure of float (and precision) in
I often use the Stack data structure in both Java and C++. This is
I am sorry if my question sounds stupid because my data structure understanding is

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.