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

2014/3/23

mouseClicked

Nagoya Nagoya

2014/3/23

#
Hello there everyone I have the question. Subclass: Play game Instructions Let's say I have two subclasses from the actor class and that I am in myWorld class ( subclass of world ) and want to create a statement which is: If you click on the "play game" box, it Goes to the game scenario. If you click on the instructions box it will show you how to play the game. How would I write this? Public void checklist() { If (Greenfoot.mouseClicked(?????)) { ???? } } How would I complete this? Thank you for all the trouble I caused!!
erdelf erdelf

2014/3/23

#
well, in the play game box
if(Greenfoot.mouseClicked(this))
{
   Greenfoot.setWorld(new GameWorld());
}
and in the instructions
if(Greenfoot.mouseClicked(this))
{
  //what ever your code to show the instructions is
}
danpost danpost

2014/3/23

#
If in the 'myWorld' world, you will need references to those actors. Either in fields: private GameBox gamebox= new GameBox(); private Instructions instructions = new Instructions(); or by getting them before checking for mouse clicks in the act method: GameBox gamebox = (GameBox)getObjects(GameBox.class).get(0); Instructions instructions = (Instructions)getObjects(Instructions.class).get(0); After which, in the 'myWorld' act method, you can use: if (Greenfoot.mouseClicked(gamebox) {....} if (Greenfoot.mouseClicked(instructions) {.... }
erdelf erdelf

2014/3/23

#
@danpost, isnt that basically the same `?
Nagoya Nagoya

2014/3/23

#
Thanks for The fast reply !
danpost danpost

2014/3/23

#
erdelf wrote...
@danpost, isnt that basically the same `?
Nagoya wrote...
Let's say I have two subclasses from the actor class and that I am in myWorld class ( subclass of world ) and want to create a statement which is: If you click on the "play game" box, it Goes to the game scenario. If you click on the instructions box it will show you how to play the game.
This is what was asked for (see the bold-italicized).
You need to login to post a reply.