I am making a bullet, that needs to disappear upon hitting the world edge. The code will be linked below - when i execute it, the bullet disappears upon hitting both X-axis world edges, as well as the bottom Y-axis world edge.
But it just gets stuck upon hitting the top Y-axis world edge.
Can someone help me why this is happening, and how i make it disappear upon hitting the top Y-axis wolrd edge aswell?
thanks
public void WorldEdge()
{
if (atWorldEdge())
{
getWorld().removeObject(this);
}
}
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth()-10)
{
return true;
}
if(getX() < 10 || getY() > getWorld().getHeight()-10)
{
return true;
}
else
{
return false;
}