Try this, and and create an if in your code where it detects if atEdge==true then do the opposite movement back
public boolean atEdge()
{
if (getX() <= *half size of actor's width* || getX() >= getWorld() . getWidth() -*half size of actor's width*)
return true;
if (getY() <= *half size of actor's height* || getY() >= getWorld() . getHeight() -*half size of actor's height*)
return true;
else
return false;
}
This will even work if your world has objects that spawn outside the area you can view in the screen.