This site requires JavaScript, please enable it in your browser!
Greenfoot back
jakeIon
jakeIon wrote ...

2016/4/27

Remove multiple objects after one has been clicked

jakeIon jakeIon

2016/4/27

#
So I'm VERY new to Greenfoot and for a project, I need to click on one object and have that object and two other objects deleted at the same time. The objects are titled: Scenario1, Scenario2, and Scenario3. I'm writing this code inside of Scenario1 and it's not working. Please help if you can!!
1
2
3
4
5
6
7
8
9
10
11
12
    public void act()
    {
    removeButtons();
}
 
public void removeButtons() {
       if(Greenfoot.mouseClicked(this)) {
           getWorld().removeObject(this);
           clear(Scenario2.class);
    }   
}
}
danpost danpost

2016/4/27

#
What class do the Scenario1, Scenario2 an Scenario3 classes extend?
jakeIon wrote...
The objects are titled: Scenario1, Scenario2, and Scenario3.
Actually, to clarify, the objects are not titled with those names -- the classes that these objects were created from are called by those names. You need to supply any object created from any class a name of your choosing for them to have names. Also, you must do so at the proper place to be usable at all the possible places you need them to be. Examples of giving objects names follows:
1
2
3
4
World world = getWorld(); // gives the world an actor is in the name 'world'
Actor scenario2 = new Scenario2(); // creates a Scenario2 object and names it 'scenario2'
MouseInfo mouse = Greenfoot.getMouseInfo(); // gets a MouseInfo object and names it 'mouse'
int counter = 0; // creates an int variable named 'counter' and assigns it a value of zero
The last one is not actually an object, but still shows that the type precedes the name you give it to indicate what the named variable can hold.
You need to login to post a reply.