Really struggling with getting the hero to stop at the world edge. I have to codes but none work.
This is kind of working. What I lean is that if I go pass X=0 it still passes but if I go to X=960 it puts me at X=0. If I make getX() <= it blocks me on the X axis at 0.
Now this code puts me at X=0 is I get pass the middel fo the world.
This is another code I made using the API but it when I try to run the game it crashes Greenfoot.
Any suggestions to stop the hero at the edge but letting everything else pass?
private void checkEdge()
{
if (getX() >= getWorld().getHeight())
{
setLocation(0, getY());
}
}public boolean isAtEdge()
{
if (getX() <= getWorld().getHeight())
{
setLocation(0, getY());
}
return isAtEdge();
}

