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

2015/11/30

Removing a specific object

Chapaladeen Chapaladeen

2015/11/30

#
public class Play extends World implements ButtonResponder { private World firstWorld; /** * Constructor for objects of class OtherWorld. */ public Play(GreenfootImage background, World Menu) { super(1920, 1080, 1); //Sets firstWorld to Menu so that it goes back to the Main Menu. firstWorld = Menu; //Adds in the title class as an object at a set position on screen. addObject(new Title(), 960, 100); //Adds in a button that will be used to go back to the Main Menu when called. addObject(new Button("1", this), 960, 250); addObject(new Button("Back", this), 380, 900); } /** * All buttons in the MenuWorld can call this method. */ public void buttonPressed(Button button) { //If the button labled Back is clicked then this statement is executed. if ("Back".equals(button.getTitle()) ) { //Changes the world back to the MainMenu class Greenfoot.setWorld(firstWorld); } if ("1".equals(button.getTitle()) ) { addObject(new Button("2", this), 960, 250); } } } All the rest of this code works, but I want to make it so that I can remove the button that was created with a "1" as text when it is clicked. Either that or I plan to update it with a "2" instead. If anyone can tell me the way to remove the button then that'd be awesome, thanks!
danpost danpost

2015/11/30

#
My Value Display Tutorial scenario may help in many aspects of what you are trying to do; including: * changing of image * referencing the buttons * removing a specific button
Chapaladeen Chapaladeen

2015/12/1

#
danpost wrote...
My Value Display Tutorial scenario may help in many aspects of what you are trying to do; including: * changing of image * referencing the buttons * removing a specific button
I can't look at the scenario currently because my college helpfully blocks stuff from the greenfoot website, also including any other websites. Is there any chance I can get some sort of explanation as I don't have the time to do this from home currently. I appreciate the advice, though.
danpost danpost

2015/12/1

#
Most of it deals with keeping a reference to the button actors (having fields in your world class that hold the buttons). Then the world act method can be used to perform the necessary actions on the buttons.
You need to login to post a reply.