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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:56:35+00:00 2026-06-06T16:56:35+00:00

My goal is getting the ball to be centered at the paddle even if

  • 0

My goal is getting the ball to be centered at the paddle even if the value of the ball radius were to change in future versions of the game.
My only problem is implementing the correct math formula
for the x coordinate of the gameball. I got the y coordinate formula working perfectly.

I do not need the correct answer. I just need guidance and suggestions to get the answer.

Here is a picture of the java program:

http://i33.photobucket.com/albums/d86/warnexus/ball.png

You can find the code below the comment “// Trouble figuring the math here”.

    /** Radius of the ball in pixels */
private static final int BALL_RADIUS = 500;


private void setup_Paddle()
{
    // TODO Auto-generated method stub

    // x coordinate of the upper left corner
    // y coordinate of the upper left corner

    paddle = new GRect(20,20,PADDLE_WIDTH,PADDLE_HEIGHT);
    paddle.setFilled(true);
    paddle.setColor(Color.PINK);
    add(paddle,paddleInitialLocationX,paddleInitialLocationY);

}

private void setup_Ball()
{

    // Trouble figuring the math here
    int ballSetUpCoordX = (int) (paddle.getX());
    // Good Code!
    int ballSetUpCoordY = (int) (paddle.getY()-BALL_RADIUS);

    gameBall = new GOval(BALL_RADIUS,BALL_RADIUS);
    gameBall.setFilled(true);
    gameBall.setColor(Color.BLUE);

    add(gameBall,ballSetUpCoordX,ballSetUpCoordY);
}

    private GOval gameBall;
    private GRect paddle;
    private int paddleInitialLocationX = 200;
    private int paddleInitialLocationY = 500;
  • 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-06T16:56:36+00:00Added an answer on June 6, 2026 at 4:56 pm

    Coordinates are generally for the top left corner of an object. So to get any two objects o1 and o2 to be centered the same place, you have to offset based on size.

    Here we’ll move o1‘s center to o2‘s center.

    int o2CenterX = o2.x - (o2.width/2);
    //If we just used o2CenterX, it would put the corner of o1 into the center of o2
    o1.x = o2CenterX - (o1.width/2);
    

    Repeat for y, which you appear to have already done(radius serves as width/2). You will likely have to adjust this formula slightly unless you want the paddle and ball intersecting on the screen.

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

Sidebar

Related Questions

I getting closer to my goal. But I am having difficulties in disabling the
Goal: Gain datatype date with year and month Problem: Need to help to convert
I'm getting close to my final goal, which is to generate a nice graph
I am having a problem getting my Pep/8 assembly program to produce the correct
I am getting the error Can't find Goal with an ID but I am
I'm getting a strange error when reading my data into an array. My goal
My goal is to just output the column data specified in the fieldList. Getting
I'm getting the below error while running the below script. My goal is to
I'm having trouble getting Code Analysis to run on the build server. My goal
I am getting started with database development (goal is azure, getting there...). I followed

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.