Sorry the API couldn't explain it to me how do you remove an actor from the world??
removeObject(>the object to be removed<);
getWorld().removeObject(this);
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;
}
}getWorld().removeObject(reference);
getWorld().removeObjects(getWorld().getObjects(ClassName));
getWorld().removeObjects(getWorld().getObjects(null));
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);
}// in your actor class:
if (Greenfoot.mouseClicked(this)) {
((YourWorldName) getWorld()).removeAllObjects();
}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.
}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);
}
}