Hi, so i have a boat class, and in a different class (Victor class) I'm trying to delete the boat, and also I need to bring back the boat at a later time. i know I have to make it into an object, but I'm not sure how to do that.


1 | getWorld().removeObjects(getWorld().getObjects(Boat. class )); |
1 | getWorld().addObject( new Boat(), /* new location coordinates */ ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // add instance field to Victor class private Boat boatRemoved = null ; // to save boat being removed if (getX() > 1800 && boatRemoved == null ) { boatRemoved = (Boat)getWorld().getObjects(Boat. class ).get( 0 ); getWorld().removeObject(boatRemoved); } // and add back into the world later with if (boatRemoved != null ) { getWorld().addObject(boatRemoved, /* new location coordinates */ ); boatRemoved = null ; } |