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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:41:26+00:00 2026-06-02T18:41:26+00:00

Now, I have been looking for the answer to this for a while, but

  • 0

Now, I have been looking for the answer to this for a while, but Google and all my power seems to fail me.

I got this Class. (MyWorld).
Within MyWorld I have an Array of objects

GameUnit m_MyUnits[] = new GameUnit[maxUnits];

Right now m_MyUnits are filled up with GameUnits and subclasses here off, and the are walking around the screen happy as cheesecake.
I have even written my own little collision detection for each of them, so they won’t bump into each other.

And all works fine, BUT!
For my collision detection to work I have chosen the slowest of ways (and most memory requiring I think)

In MyWorld I first loop trough each GameUnit and gets its X and Y position for an array
private int[][] Positions = new int[2][maxUnits]);

I then loop trough each and every GameUnit and assigns this array to it. (GameUnit has its own array called Positions for this)

Now, while this works, I can’t help but think that this is stupid like …. Well, I won’t use those words here.

Is there a way for GameUnit to Call the Positions in MyWorld, or even better, for the game unit to call the Array m_MyUnits[].getX() and m_MyUnits[].getY() in MyWorld
Some thing like this (I use Parent to refer to MyWorld from the GameUnit)

For(int i = 0;i < Parent.maxUnits;i++) {
  int targetX = Parent. m_MyUnits[i].getX();
  int targetY = Parent. m_MyUnits[i].getX();
  //Do some thing like collition detection with the data.
}

Is this possible, or?

Yours JavaApprentis.

  • 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-02T18:41:28+00:00Added an answer on June 2, 2026 at 6:41 pm

    When you create a GameUnit, you could pass the MyWorld as a constructor argument. The GameUnit constructor could then store the MyWorld object in a member variable. Then when it needed to do collsion detection, it could ask the MyWorld for a list of potential partners by calling a method on that object.

    In GameUnit:

    private MyWorld myWorld;
    
    public GameUnit(int,int,double, MyWorld m) {
        myWorld = m;
    }
    

    And then in MyWorld, when you make a GameUnit:

    new GameUnit(1, 2, 1.0, this);
    

    Then in all the methods of GameUnit, you have the MyWorld object in myWorld available for use.

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

Sidebar

Related Questions

I've been looking for the answer to this question for a while now but
I have been looking all over for an answer to this question, but can't
I've been looking for this for a while, but haven't found an answer (blame
I've been looking for an answer to this question for a while now. I
I've been looking for a solution to this for a while now, have found
I have been looking for an answer to this problem for some time now
Good morning. I have been looking all over trying to answer this question. If
I have been looking for an answer for some time now, hope you could
I've been looking at this Stackoverflow question and have the answer implemented. It works
Have been searching over the Graph API docs, looking for the answer to this.

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.