Sorry the API couldn't explain it to me how do you remove an actor from the world??


1 | removeObject(>the object to be removed<); |
1 | getWorld().removeObject( this ); |
1 2 3 4 5 6 7 | public void act() { Actor actor = getOneIntersectingObject(Actor. class ); if (actor != null ) { getWorld().removeObject(actor); //if you want to remove an object from an actor class you have to use getWorld().removeObject; } } |
1 | getWorld().removeObject(reference); |
1 | getWorld().removeObjects(getWorld().getObjects(ClassName)); |
1 | getWorld().removeObjects(getWorld().getObjects( null )); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public void act() { if (Greenfoot.mouseClicked( this )) { getWorld().removeObjects(getWorld().getObjects( null )); addobjects(); } } public void addobjects(){ getWorld().setBackground( new GreenfootImage( "modification background.fw.png" )); //this line then comes up with a nullpointerexception getWorld().addObject( new skisbutton(), 3 , 2 ); getWorld().addObject( new tracksbutton(), 5 , 2 ); getWorld().addObject( new wheelsbutton(), 7 , 2 ); getWorld().addObject( new largebaybutton(), 7 , 3 ); getWorld().addObject( new mediumbaybutton(), 5 , 3 ); getWorld().addObject( new smallbaybutton(), 3 , 3 ); getWorld().addObject( new backbutton(), 8 , 7 ); } |
1 2 3 4 | // in your actor class: if (Greenfoot.mouseClicked( this )) { ((YourWorldName) getWorld()).removeAllObjects(); } |
1 2 3 4 5 6 | public void removeAllObjects() { removeObjects(getObjects( null )); addObject( new skisbutton(), 3 , 2 ); // add all the other objects you want to add, but remove the 'getWorld().' part at the beginning from it. } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class modifybutton here. * * @author (your name) * @version (a version number or a date) */ public class modifybutton extends buttons { public int traction= 0 ; public int baysize= 0 ; /** * Act - do whatever the modifybutton wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.mouseClicked( this )) { //code to get rid of actor called playbutton from world called world getWorld().setBackground( new GreenfootImage( "modification background.fw.png" )); //this line then comes up with a nullpointerexception getWorld().addObject( new skisbutton(), 3 , 2 ); getWorld().addObject( new tracksbutton(), 5 , 2 ); getWorld().addObject( new wheelsbutton(), 7 , 2 ); getWorld().addObject( new largebaybutton(), 7 , 3 ); getWorld().addObject( new mediumbaybutton(), 5 , 3 ); getWorld().addObject( new smallbaybutton(), 3 , 3 ); getWorld().addObject( new backbutton(), 8 , 7 ); } } |