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

2012/11/9

How do you make an item which is clicked change the background?

tobi1066 tobi1066

2012/11/9

#
I just joined greenfoot today and I know nothing about java. Please explain the different parts of the code.this is my code: public class Crabmenu extends Actor { public void act() { if (Greenfoot.mouseClicked(this)) { new Sandbg(); } } }
tobi1066 tobi1066

2012/11/9

#
Please help asap.
danpost danpost

2012/11/10

#
>> public class Crabmenu extends Actor The class identifier; the bracket that follows and its matching pair enclose the fields and methods for the class { >> public void act() A method identifier: the bracket that follows and its matching pair enclose the fields and instructions The 'public' means that it can be called from the world or another actor class as well as from its own class. The 'void' means that no information will be returned when exiting the method. All 'act' methods for all objects in the world, and the world, are called in rotation, continuously. Each set of calls is called a frame. { >> if (Greenfoot.mouseClicked(this)) The conditional statement above checks to see if the object that triggered executing the act method was clicked on by the mouse. If so, the statements in the following block (between the brackets) will execute. { >> new Sandbg(); The statement is really meaningless. It creates a new Sandbg object, but does nothing with it. That is, it is not being held in a field and it is not being added to the world. It is basically lost as nothing else happens in this method. } } }
tobi1066 tobi1066

2012/11/11

#
Danpost wrote...
{ >> new Sandbg(); The statement is really meaningless. It creates a new Sandbg object, but does nothing with it. That is, it is not being held in a field and it is not being added to the world. It is basically lost as nothing else happens in this method. }
Thank you for the help - but how do I add it to the world?
SPower SPower

2012/11/11

#
getWorld().addObject(new Sandbg(), x, y);
You need to login to post a reply.