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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:23:18+00:00 2026-06-11T06:23:18+00:00

I´ve been debugging this for hours now. Detecting collision. this code bellow works fine.

  • 0

I´ve been debugging this for hours now. Detecting collision. this code bellow works fine.

while (numberOfTurns >= 0)                                      
            {   
        GObject collision = getElementAt(ball.getX(),ball.getY());
        }

It will get any graphical object the ball collides with on screen and return it. However, this is not how I want to design the program. But instead make a seperate method for collision detection, like bellow:

    while (numberOfTurns >= 0)                                      
        {   
        getCollidingObject();
        }

Here is the method, it just returns itself

private GObject getCollidingObject()
{       
    return getElementAt (ball.getX(),ball.getY());
}

then I assign it to this private instance variable

private GObject collider = getCollidingObject();

But!!! it does not work, it just returns null. the first code snippet i posted works fine… anyone knows what is happening here?

  • 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-11T06:23:19+00:00Added an answer on June 11, 2026 at 6:23 am

    You say that you’re assigning the return value of getCollidingObject() to a private instance variable. With the code you posted, that call is being made once on construction of your object, not every time you want the result. Try:

    while (numberOfTurns >= 0)                                      
        {   
        GObject collision = getCollidingObject();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been staring at this code for few hours, tried walkthrough,debugging with autos
I've been debugging this code for hours, I think I would benefit from someone
We've been debugging this JBoss server problem for quite a while. After about 10
I've been debugging this error for the last 2 hours, and knowing myself I
I've been debugging this one application for a while and it led me to
I been debugging REP STOS DWORD PTR ES:[EDI] for a while now From my
I've been getting an error recently while debugging an ASP.NET application in Visual Studio
Been trying to sort this one out for a while. I'd really appreciate any
Been hustling with this for a while but cant still get the page to
I've been pulling my hair out for the last few hours with this problem.

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.