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

2017/3/6

how to create the play button on the screen?

Ajis Ajis

2017/3/6

#
I want to make the play button on the screen at Greenfoot what can i do?
danpost danpost

2017/3/6

#
A button is just an Actor object with one or more possible images that clicks are detected on. I consider a button to be a simple Actor object, meaning no state or implementation need be added into its class. You could simply have this class, which is the entire class:
1
public class SimpleActor extends greenfoot.Actor {}
Then, create an object from the class, give it an image and test for clicks on it:
1
2
3
4
5
6
7
8
9
// instance reference field for the button
Actor playButton = new SimpleActor();
 
// in constructor
playButton.setImage("play.png"); // adjust name as needed
addObject(playButton, << wherever >>);
 
// in act method
if (Greenfoot.mouseClicked(playButton)) Greenfoot.setWorld(new GameWorld()); // adjust 'GameWorld' name as needed
All this is touched upon in my Value Display Tutorial scenario.
You need to login to post a reply.