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

  • Home
  • SEARCH
  • 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 7743011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:25:26+00:00 2026-06-01T09:25:26+00:00

I currently have objects populating the screen randomly and bouncing around the stage. The

  • 0

I currently have objects populating the screen randomly and bouncing around the stage. The problem is, some of the objects are getting stuck and bouncing back and forth rapidly between two points. How can I prevent this?

Here’s how I have the EnterFrame setup:

var ballT = e.target
ballT.x +=  ballT.vx;
ballT.y +=  ballT.vy;

if (ballT.x + ballT.width / 2 >= sWidth || ballT.x - ballT.width / 2 <= 0) {
    ballT.vx =  -  ballT.vx;
} else if (ballT.y + ballT.height / 2 >= sHeight || ballT.y - ballT.height / 2 <= 0) {
    ballT.vy =  -  ballT.vy;
}

Any ideas or any good reads worth checking out?

  • 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-01T09:25:28+00:00Added an answer on June 1, 2026 at 9:25 am

    Most likely, your objects are going a bit “too much out of bounds”, so that when you turn them around, they don’t make it inside the bounds before you turn them around again. You may want to change the code to be a bit more clear on when to turn things around;

    var ballT = e.target
    ballT.x +=  ballT.vx;
    ballT.y +=  ballT.vy;
    
    // Outside to the right and heading right - turn around
    if ( ballT.x + ballT.width / 2 >= sWidth && ballT.vx > 0 )
        ballT.vx = -ballT.vx;
    
    // Outside to the left and heading left - turn around
    if ( ballT.x - ballT.width / 2 <= 0 && ballT.vx < 0 )
        ballT.vx = -ballT.vx;
    
    // Outside at the bottom and heading down - turn around
    if ( ballT.y + ballT.height / 2 >= sHeight && ballT.vy > 0 )
        ballT.vy = -ballT.vy;
    
    // Outside at the top and heading up - turn around
    if ( ballT.y - ballT.height / 2 <= 0 && ballT.vy < 0 )
        ballT.vy = -ballT.vy;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following objects persisting successfully: Person first name, etc. Exams title,
I currently have a bunch of SQLCHAR objects from a database query. The query
Currently I have a lot of python objects in my code similar to the
I have a ComboBox with a list of objects bound to it. Currently i
I have Transaction objects that are combined in a Cart object. Some Transaction objects
I currently have a database that consist of many linked objects. Simplified with less
I'm developing an application which currently have hundreds of objects created. Is it possible
I currently have an ArrayList holding objects of a class I have created, I
Currently I have an object which I receive from a server, this contains two
Currently I have a DataModel object which contains my linq to sql classes(a dmbl

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.