how do you make one object go through one edge and go out the other?


1 2 3 4 | if (getX() == getWorld().getWidth- 1 ) { setLocation( 1 , getY()); } if (getY() == getWorld().getHeight- 1 ) { setLocation(getX(), 1 ); } if (getX() == 0 ) { setLocation(getWorld.getWidth()- 1 , getY()); } if (getY() == 0 ) { setLocation(getX(), getWorld().getHeight()- 1 ) } |
1 2 3 4 5 6 | private void moveObject() { int dX = object.HorizontalSpeed; int dY = object.VerticalSpeed; setLocation((getX() + dX + getWorld.getWidth()) % getWorld.getWidth(), (getY() + dY + getWorld.getHeight()) % getWorld.getHeight()); } |