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?
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: