The Greenfoot Programmers' ManualVersion 1.0for Greenfoot 1.5.1
Michael Kölling, Martin Pain
University of Kent
Copyright © M Kölling, 2006, 2009 The Greenfoot Programmers' Manual is licensed under a
Contents
1 IntroductionGreenfoot is a software tool designed to let beginners get experience with object-oriented programming. It supports development of graphical applications in the Javatm Programming Language. For tutorials, videos and a quick-start guide for Greenfoot, see the 'Getting Started' section on http://greenfoot.org/programming/ This manual is an introduction to programming in Greenfoot. It starts from the start: We first discuss how to create a new scenario, then how to create worlds and actors, and so on. This may not be the order in which you approach your own personal Greenfoot programming experience. In fact, probably the most common way for people to start programming in Greenfoot is by modifying an existing scenario. In that case, you already have a scenario, a world, and one or more actor classes. Feel free to jump right into the middle of this manual and start reading there. You may, for instance, be interested in generating actor images in a certain way, or in dealing with collisions. The secitons in this manual were written with the goal that they can be read independently - there is no strong need to read everything in order. Every now and then, when it is useful to refer to examples, we will use the 'wombats', 'ants', 'balloons' and 'lunarlander' scenarios as examples. All these scenarios are included in the standard Greenfoot distribution. You can find them in the 'scenarios' folder. Have fun!
2 Creating a new scenario
Doing this is easy: choose 'New' from the 'Scenario' menu, and select a location and name for your scenario. Greenfoot will create a folder with that name that contains all files associated with your scenario.
Both 'World' and 'Actor' are abstract classes - that is: you cannot create any objects of them. Especially, there is no world object at the moment, because we have no finished world class to make a world object from. As a result, even if we had an actor object now, we could not place it anywhere, because we cannot create a world. In order to progress from here, we need to create subclasses (that is: special cases) of World and of Actor. In other words: we have to define our own world, and then we have to define one or more of our own actors. That's what we'll start in the next section. On the Grenfoot website there is a tutorial video available that shows how to create and set up a new scenario. 3 Using the API
You can select the 'Greenfoot Class Documentation' option from Greenfoot's Help menu (right) to open the API documentation in a web browser, or double-click on the World or Actor classes. The API is distributed with Greenfoot, so you do not need to be connected to the Internet to view it. Greenfoot provides five classes that you should know about. They are World, Actor, Greenfoot, GreenfootImage and MouseInfo. The World and Actor classes serve as superclasses for our own world and actor classes - we have seen them in the class display. 'GreenfootImage' is a class that provides images and image drawing methods for us to use with our worlds and actors. 'Greenfoot' is a class that gives us access to the Greenfoot framework itself, such as pausing the execution or setting the speed. 'MouseInfo' is a class that provides information on mouse input, such as the co-ordinates of where the mouse was clicked and what actor was clicked on. All of these classes will be mentioned more below. While you are programming in Greenfoot, it is often a good idea to have the API available to you, either printed out or in a web browser window. 4 Creating a world
After choosing a name for your new world and clicking Ok, you should see the new world in the class display. Your new world class will have a skeleton that is valid and compiles. You can now compile your scenario, and you will notice that the new world is automatically visible in the world view. This is one of the built-in features of Greenfoot: whenever a valid world class exists, Greenfoot will, after every compilation, create one world object and show it in the world display. In theory, you could have multiple world subclasses in a single Greenfoot scenario. It is non-deterministic, though, which of those world will then be automatically created. You could manually create a new world using the world's constructor, but in practice we usually have only a single world subclass in every scenario. World size and resolutionLet us have a closer look at the code inside the new world class. The default skeleton looks something like this: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class MyWorld extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 20x20 cells with a cell size of 10x10 pixels.
super(20, 20, 10);
}
}
The first things we have to decide are the size of our world and the size of its cells. There are essentially two kinds of worlds: those with large cells, where every actor object occupies only one single cell (that is: the cell is large enough to hold the complete actor), and those with small cells, where actors span multiple cells. You have probably seen examples of both. 'wombats', for example, is one of the first kind, whereas 'ants' is of the second kind. (The wombats and ants scenarios are distributed as examples together with Greenfoot. If you have not looked at them, and are not sure what we are discussing here, it would be a good idea to look at them now.) We can specify the world size and cell size in the super call in the constructor. Assume we change it to super(10, 8, 60); In this case, we will get a world that is 10 cells wide, 8 cells high, and where every cell is 60x60 pixels in size. The signature of the World class constructor (which we are calling here) is public World(int worldWidth, int worldHeight, int cellSize) All positioning of actors in the world is in terms of cells. You cannot place actors between cells (although an actor's image can be larger than a cell, and thus overlap many cells). Large cell / small cell trade-offThe trade-off to be made when choosing a world's cell size is between smooth motion and ease of collision detection. One result of the fact that actors can only be placed in cells is that worlds with large cells give you fairly course-grained motion. The wombats scenario, for instance uses a 60-pixel sized cell, and thus, when wombats move one step forward, their image on screen moves by 60 pixels. On the other hand, in worlds with large cells, where the actors are completely contained inside a cell, detecting other actors at one actor's position is a bit simpler - we do not need to check for overlapping images, but simply for the presence of other actors in the same cell. Finding actors in neighbouring cells is also easy. We will discuss this in more detail in the section 'Detecting other objects (collisions)', below. If you want smoother motion, you should use a smaller cell size. the 'ants' scenario, for example, uses 1-pixel cells, giving the ants the ability to move in small steps. This can also be combined with large actor objects. The 'lunarlander' scenario, for instance, uses a large actor (the rocket) on a 1-pixel cell world. This gives the actor very smooth motion, since it's location can be changed in one-pixel intervalls. World background imagesMost of the time, we want our world to have a background image. This relatively easy to do. First, you have to make or find a suitable background image. There are a number of background images distributed with Greenfoot. You can set one of these as the world's background either when you create the class, or by selecting 'Set image...' from the class's popup menu. Select the 'backgrounds' category from the categories box, select an image and click Ok. There are more background images available in the Greenfoot Image Collection on the Greenfoot web site.To use a custom image, such as one from the Greenfoot Image Collection or one you have created yourself, place the image file into the 'images' folder inside your scenario folder. Once the image file is there, it is available to your Greenfoot scenario, and you can select it from the 'Scenario images' box in the 'Set image' or 'New subclass' dialog. You can also set the background image in the Java code with the line: setBackground("myImage.jpg");
where "myImage.jpg" should be replaced with the correct image file name. For example, assume we have placed the image "sand.jpg" into our scenario's 'images' folder, then our world's constructor might look like this: public MyWorld()
{
super(20, 20, 10);
setBackground("sand.jpg");
}
The background will, by default, be filled with the image by tiling the image across the world. To get smooth looking background, you should use an image whose right edge fits seamlessly to the left, and the bottom to the top. Alternatively, you can use a single image that is large enough to cover the whole world. If you want to paint the background programmatically you can easily do so instead of using an image file. The world always has a background image. By default (as long as we do not specify anything else) it is an image that has the same size as the world and is completely transparent. We can retrieve the image object for the world's background image and perform drawing operations on it. For example: GreenfootImage background = getBackground();
background.setColor(Color.BLUE);
background.fill();
These instructions will fill the entire bakground image with blue. A third option is to combine the two: You can load an image file, then draw onto it, and use the modified file as a background for the world: GreenfootImage background = new GreenfootImage("water.png");
background.drawString("WaterWorld", 20, 20);
setBackground(background);
Background images are typically set only once in the constructor of the world, although there is nothing that stops you from changing the world's background dynamically at other times while your scenario is running. Showing tilesSometimes, when you have worlds with large grid sizes, you want to make the grid visible. The 'wombats' scenario does this - you can see the grid painted on the background of the world. There is no special function in Greenfoot to do this. This is done simply by having the grid painted on the image that is used for the world background. In the case of 'wombats', the world has 60-pixel cells, and the background image is a 60x60 pixel image (to match the cell size) that has a one pixel line at the left and top edges darkened a bit. The effect of this is a visible grid when the tiles are used to fill the world background. The grid can also be drawn programatically onto the background image in the world constructor. Here is an example: private static final Color OCEAN_BLUE = new Color(75, 75, 255); 5 Creating new actorsThis section discusses some of the characteristics of actor classes, and what to consider when writing them. All classes that we want to act as part of our scenario are subclasses of the built-in 'Actor' class. We can create new actor classes by selecting 'New subclass...' from the Actor class's popup menu. The following dialogue lets us specify a name and an image for our new class. The name must be a valid Java class name (that is: it can contain only letters and numbers). The class image will be the default image for all objects of that class. Class imagesEvery class has an associated image that serves as the default image for all objects of that class. Every object can later alter its own image, so that individual objects of the class may look different. This is further discussed in the section 'Dealing with images', below. If objects do not set images explicitly, they will receive the class image. The image selector in the dialogue shows two groups of images: project images and library images. The library images are included in the Greenfoot distribution, the project images are stored in the 'images' folder inside your scenario (project) folder. If you have your own images that you like to use for your class, you have two options:
InitialisationAs with most Java objects, the normal initialisation of the object happens in the object's constructor. However, there are some initialisation tasks that cannot be finished here. The reason is that, at the time the object is constructed, it has not been entered into the world yet. The order of events is:
During step 1, the object's constructor is executed. Since the object is not in the world at this time, methods such as getWorld(), getX() and getY() cannot be called in the constructor (when you're not in the world, you do not have a location). So, if we want to do anything as part of our initialisation that needs access to the world (such as create other objects in the world, or set our image depending on neighbouring objects), it cannot be done in the constructor. Instead, we have a second initialisation method, called 'addedToWorld'. Every actor class inherits this method from class 'Actor'. The signature of this method is public void addedToWorld(World world) This method is automatically called when the actor has been added to the world. So, if we have work to do at the time the object has been added, all we have to do is to define an 'addedToWorld' method in our class with this signature and place our code there. For example: public class Rabbit extends Actor
{
private GreenfootImage normalImage;
private GreenfootImage scaredImage;
public Rabbit()
{
normalImage = new GreenfootImage("rabbit-normal.png");
scaredImage = new GreenfootImage("rabbit-scared.png");
}
public void addedToWorld(World world)
{
if(isNextToFox()) {
setImage(scaredImage);
}
else {
setImage(normalImage);
}
}
private boolean isNextToFox()
{
... // calls getWorld() to check neighbours in world
}
}
In this example, the intention is that a rabbit, when placed into the world, looks 'normal' if it is not next to a fox, but looks scared when placed next to a fox. To do this, we have two image files ("rabbit-normal.png" and "rabbit-scared.png"). We can load the images in the Rabbit's constructor, but we cannot select the image to show, since this involves checking the world, which is not accessible at the time the constructor executes. When a user places an object into the world, things happen in this order:
In our example above, by the time the addedToWorld method is called, the object is in the world and has a location. So we can now call our own isNextToFox() method (which presumably makes use of the world and our location). The setLocation method will be called every time the location of the object changes. The addedToWorld method is called only once. The 'Lander' class in the 'lunarlander' scenario (from the Greenfoot sample scenarios) shows another example of using this method.
6 Making things moveEvery time a user clicks the 'Act' button on screen, the 'act' method of each object in the world will be called. The 'act' method has the following signature: public void act() Every object that is active (i.e. is expected to do something) should implement this method. The effect of a user clicking the 'Run' button is nothing more than a repeated (very fast) click on the 'Act' button. In other words, our 'act' method will be called over and over again, as long as the scenario runs. To make object move on screen, it is enough to modify the object's location. Three attributes of each actor become automatically and immediately visible on screen when you change them. They are:
If we change any of these attributes, the appearance of the actor on screen will change. The Actor class has methods to get and set any of these.
|
![]() |
![]() |
Without the diagonal: |
With the diagonal: |
A method related in functionality to the getNeighbours methods:
List leaves = getObjectsInRange(2, Leaf.class);
This method call will return all objects (of the class Leaf and subclasses) that have a location that is within 2 cells. If the distance between two actors is exactly 2, it is considered to be in range. See the picture below for an illustration of this
![]() |
getObjectsInRange(2, Leaf.class); |
Sometimes it is not precise enough to use the cell location to determine collisions. Greenfoot has a few methods that allow you to to check whether the graphical representations of actors overlap.
Actor leaf = getOneIntersectingObject(Leaf.class);
List leaves = getIntersectingObjects(Leaf.class);
Be aware that these method calls require more computation than the cell based methods and might slow down your program if it contains many actors.
There are two ways that the keyboard can be used in Greenfoot scenarios: holding a key down for a continuous action, or pressing a key for a discrete action.
Keys on the keyboard, when being passed to or returned from a method, are referred to by their names. The possible names are:
The lunarlander example scenario uses this method: while the 'down' cursor key is pressed the lander's thruster is fired. This is achieved using the isKeyDown() method of the Greenfoot class. In an actor's act method you can call this method with a key's name as the parameter, and it will return true if that key is currently being held down. You can use this in the condition of an if-statement to make the actor act differently or look different, depending on whether the key is down or not:
if(Greenfoot.isKeyDown("down")) {
speed+=thrust;
setImage(rocketWithThrust);
} else {
setImage(rocket);
}
In this method, when referring the the alphabetical keys either the uppercase or lowercase letters can be used as the parameter to the method.
The getKey() method of the Greenfoot class can be used to get the name of the most recently pressed key since the previous time the method was called. This can be used for single actions where the key is to be hit once, rather than held down, such as a 'fire bullet' action:
if(Greenfoot.getKey().equals("space")){
fireGun();
}
When comparing strings, unlike comparing numbers, it is much better to use the string's equals method than to use the == equality operator, as strings are objects (like actors are objects) and the == equality operator, when used on objects, tests to see if they are the same object, not if they have the same contents.
Note that as the method returns the last key pressed down since the last time it was called, if the method has not been called for a while then the key returned might not have been pressed recently - if no other key has been pressed since. Also, if two keys are pressed at once, or close together between two calls of getKey, then only the last one pressed will be returned.
You can test if the user has done anything with the mouse using these methods on the Greenfoot class: mouseClicked, mouseDragged, mouseDragEnded, mouseMoved and mousePressed. Each of these methods take an object as a parameter. Usually this will be an Actor to find out if the mouse action (click, drag over, move over, etc) was on or over that actor. The parameter can also be the world object, which finds out if the mouse action was over an area where there were no actors, or null which finds out if that mouse action happened at all irrespective of what actor it was over.
If the appropriate mouse action has been performed over the specified actor or world then the method returns true, otherwise it will return false. If the mouse action was over a number of actors, only the top one will return true. These methods will only return true for the world if the mouse action was not over any actors at all.
If the methods are called from an actor's act method then usually the parameter will be that actor object, using the this keyword. For example, an actor could use the following code to change its image when it is clicked. clickedImage would be a field containing a GreenfootImage object, but the this keyword is not a variable and so does not need to be defined anywhere.
if(Greenfoot.mouseClicked(this)){
setImage(clickedImage);
}
The mousePressed method is used to find out if the mouse button was pressed down, whether or not it has been released again yet. mouseClicked is used to find out if the mouse has been released after it has been pressed. That is, it finds out if the mouse has been pressed and released. mouseMoved is used to find out if the mouse has been moved over the specified object (while the button is not pressed down). mouseDragged is used to find out if the mouse has been moved over the object with the mouse button pressed down. mouseDragEnded is used to find out if the mouse has been released after having been dragged.
Additional information can be acquired from a MouseInfo object returned from the getMouseInfo method. Using this object you can find out the actor that the action was on or over (if any), the button that was clicked (i.e. left or right mouse button), the number of clicks (single or double), and the x and y co-ordinates of the mouse.
This information is used by the balloons example scenario. The mouseMoved method (using null as the parameter as the move does not have to be over a specific actor) and the getX and getY methods of the MouseInfo object are used to move the dart around:
if(Greenfoot.mouseMoved(null)) {
MouseInfo mouse = Greenfoot.getMouseInfo();
setLocation(mouse.getX(), mouse.getY());
}
The mouseClicked method is used to pop the balloons. The getActor method of the MouseInfo class is not used in this case, as it will always return the dart, and the point at which we want to test for a balloon is not where the mouse is, it is at the tip of the dart.
A tutorial video about handling mouse input is available on the Greenfoot website.
Playing a sound in Greenfoot is extremely simple. All you have to do is copy the sound file to be played into your scenario's sounds folder, and then call the Greenfoot class's playSound method with the name of the sound file to be played.
For example, the lunarlander scenario plays a sound file called Explosion.wav if the lander crashes into the moon's surface. This file is in the lunarlander/sounds folder, and is played by the following line of code:
Greenfoot.playSound("Explosion.wav");
The audio file must be a wav, aiff or au file. Mp3 files are not supported, and not all wav files are supported. If a wav file does not play, it should be converted to a "Signed 16 bit PCM" wav file. This can be done with many audio programs, for example the excellent and free "Audacity" has an Export function that will do the conversion.
Sound file names are case-sensitive (i.e. "sound.wav", "Sound.wav" and "sound.WAV" are all different); if you use the wrong case you will get an IllegalArgumentException as the sound will not be able to be played.
The Greenfoot class provides methods to control the execution of the scenario, and the World class provides methods to control how the scenario looks, as well as to react to the scenario stopping or starting. The Greenfoot class allows you to stop, start, pause (delay) and set the speed of the action (as well as providing the mouse, keyboard & sound methods mentioned earlier). The World class allows you to set the order in which the actors are painted on the screen, set the order in which the actors have their act method called, respond to the scenario being started and respond the the scenario being stopped.
The Greenfoot.stop() method allows you to stop the scenario, which is usually done when everything has finished.
if(getY() == 0){
Greenfoot.stop();
}
Calling the stop method is equivalent to the user pressing the Pause button. The user can then press Act or Run again, but in the example code above as long as the if-statement's condition returns true every time it is called after the scenario should stop then pressing the Run button again will have no effect.
You can set the speed of execution using the Greenfoot.setSpeed() method. It is good practice to set the suggested speed in the World's constructor. This following code sets the speed at 50%:
Greenfoot.setSpeed(50);
The Greenfoot.delay() method allows you to suspend the scenario for a certain number of steps, which is specified in the parameter. Note that the length of time that the scenario will be delayed for will vary a great deal, based on the speed of execution.
Greenfoot.delay(10); //Pause for 10 steps
All actors will be delayed when the delay method is called; if you want some actors to continue moving, or may in the future want to add an actor that continues moving during that time, then it would be better to have a boolean field or method that is false when you want to delay and true the rest of the time. Then all the actors that should stop can check at the beginning of their act methods:
public void act(){
if(!isPaused()){
...
}
}
The Greenfoot.start() method is very rarely used, as most of the code that is written in scenarios is only executed after the scenario has been started. However, while the scenario is stopped the user can call methods of the actors in the world form their popup menus. In this situation, calling Greenfoot.start() from within a method will make sure that the scenario starts running if the method is called from the popup menu.
For example, in the balloons scenario you can start the scenario, allow some balloons to appear, pause the scenario and then call the pop method on each balloon. If you added the following code to the pop method then the scenario would re-start as soon as a user tried to pop a balloon through the popup menu.
public void pop()
{
Greenfoot.start();
...
}
The setPaintOrder method of the World class sets the order in which the actors are painted onto the screen. Paint order is specified by class: objects of one class will always be painted on top of objects of some other class. The order of objects of the same class cannot be specified. Objects of classes listed first in the parameter list will appear on top of all objects of classes listed later. Objects of a class not explicitly specified effectively inherit the paint order from their superclass.Objects of classes not listed will appear below the objects whose classes have been specified.
This method is usually only called from the constructor of your subclass of World, such as in the ants scenaro:setPaintOrder(Ant.class, Counter.class, Food.class, AntHill.class, Pheromone.class);
where objects of the Ant class would always appear above (that is, completely visible when they overlap) actors of other classes.
To call the method from within an actor class, you would first have to get the current world object using the getWorld() method:
getWorld().setPaintOrder(MyActor.class, MyOtherActor.class);
The setActOrder method of the World class sets the order in which the actors act() methods are called. Similar to setPaintOrder, the act order is set by class and the order of objects of the same class cannot be specified. When some classes are not specified in a call to setActOrder the same rules apply as for setPaintOrder.
In each turn (such as one click of the Act button) the act method will be called on every object of the class which was listed first in the call to setActOrder, then on every object of the class which was listed second, and so on.
When the scenario is started Greenfoot will call the started method of the current world object, and when the scenario is stopped it will call the stopped method. If you want to run some code when these events happen, override these methods in your subclass of World. To 'override' a method in a subclass, you simply declare a method with the same name, such as how you override the act method from Actor in every subclass of it that you create.
public void started(){
// ... Do something when the scenario has started
}
public void stopped(){
// ... Do something when the scenario has stopped
}
There are a number of reusable classes available to use in your projects. These can help you achieve effects and functionality in your scenarios that would take a long time to program on your own, or that you do not have the programming experience to achieve. Some of the support classes are actors themselves that you can put straight into your scenaros (such as Explosion), some are abstract subclasses of Actor which you have to subclass with your own Actors to provide some extra functionality to those Actors (such as SmoothMover), and some are not actors at all, but utilities which actors can use (such as Vector, as used by SmoothMover).
There is a list of official Greenfoot support classes at http://greenfoot.org/programming/classes.html. There is also a collection of support classes on the Greenfoot Gallery at http://greenfootgallery.org/collections/4. To use any of the support classes, you first have to download their source code. On the list of official useful classes, clicking the name of the class will show you its source code. You can also right-click the link to save the .java source file. On the gallery, click on the name of a scenario to go to its page. There you can try out the scenario, or click the Download the source for this scenario link above it.
There are two ways to copy a support class into your own scenario. The simplest is to create a class of the right name in your scenario, then copy the entire contents of the support class's source and paste it over the entire contents of the class you just created in your scenario. The other way is to save the files for that class into your scenario folder. If you are using a support class from the official list, then save the .java file into your scenario folder. If you are using a class from a gallery scenario, copy across the file with the same name as the class with a .java extention from the gallery scenario's folder to your scenario's folder. (You can also copy across the files with the same name as the class and the .class and .ctxt extentions, but you do not have to.)
Note that some support classes use other support classes, images or sounds, so you may have to copy them in to your scenario to use the class. (For example, the SmoothMover abstract actor requires the Vector support class, and the Explosion actor requires an image and a sound to be copied into the images and sounds folders respectively.)
Once you have copied a reusable actor into your class, it should be ready to use like any other actors in your scenario - you can create instances of it, create subclasses of it, set its image and edit its source code.
Some support classes are abstract. This means that you cannot create instances of them - you cannot place them directly on the world - similar to how the Actor class itself works. To use them, create actors which are subclasses of the abstract classes - either by clicking New subclass from the popup menu, or by changing the class after the extends keyword in an actor's source to the abstract class. For example, to make an existing actor called MyActor a subclass of the SmoothMover class, change the appropriate line in the MyActor class source code from:
class MyActor extends Actor
to:
class MyActor extends SmoothMover
MyActor will still be extending Actor as SmoothMover extends Actor and MyActor extends SmoothMover.
To use the support classes that are not actors or abstract actors, you copy them into your scenario the same way as the other support classes. As they are not actors you cannot place them in the world - they are made to be used by the source code of the actors. For example, the Vector support class is used to store a motion vector (a direction and velocity) which is used by the SmoothMover class to store its movement. These classes can be created, stored in variables and have their methods called like any other objects.
If you create a class which you would like to share, create a scenario demonstrating the class and upload it to the Greenfoot Gallery with the demo tag, making sure you include the source code. Other users of the gallery will be able to view it, try it out, leave feedback and download it for their own use, and it may be added to the Support classes collection.
Greenfoot provides you with three ways to export your scenario, all available from the Export... option under the Scenario menu. The three options available to you are:
The greenfoot gallery is at http://www.greenfootgallery.org and provides a way for Greenfoot users to share their scenarios with other people, try out other people's scenarios and both give and receive feedback.
By publishing your scenario to the greenfoot gallery you are making it publicly available to anyone who visits the site. If you only wish to share your scenario with specific people, export it as an application and distribute it by email.
To publish a scenario to the gallery you will need a gallery account. You can create an account by following the link from the gallery homepage or clicking the Create account link at the bottom of the export dialog in Greenfoot. You will need to create an account once, then each time you wish to publish a scenario you enter your username and password in the export dialog.
The Publish page of the export dialog box provides you with fields to enter information to be published with your scenario.Each scenario on the gallery has an icon, which is part of a sceenshot of the scenario. You can select what that icon should show the Scenario icon box. It shows a picture of the scenario as it is at the moment. You can use the slider next to the box to zoom in and out, and you can drag the image around in the box (after you have zoomed in) to select the exact area you want the icon to show. If you run the scenario and pause it in the middle, then your icon can show what the scenario looks like while it is running, which is useful if your main actors are not visible in the world at the beginning of the scenario.
Enter a title for your scenario, a short description and a full description. The short description will be shown next to your scenario when it is displayed in a list, such as a search results page. The full description will be displayed above your scenario on the gallery, and can include an explaination and instructions for using the scenario. If you have your own webpage about this scenario you can enter its URL to provide a link to it on the gallery.
The Greenfoot gallery organises scenarios by means of tags. Select some of the commonly used tags if they are relevant to your scenario, and add any tags of your own. Tags should usually be one word long, or a small number of words connected by hyphens, and each tag should be typed on a new line in the textbox. Have a look at the tag cloud on the homepage of the gallery for ideas about what tags might be appropriate. It is always a good idea to re-use tags that other authors have already used so that similar scenarios can be grouped together. The popular tags provided for you in the export dialog are:
There are two additional options which you can select for your scenario. If you check the Publish source code check box then other users of the gallery will be able to download your scenario to see its source code, and play around with it on their computers (however that will not affect the version on the gallery). If you select this option your scenario will have the with-source tag added to it when it is published.
The Lock scenario option allows you to prevent users of your scenario from changing the speed of execution and dragging objects around the world before the scenario is run. If you uncheck this box then users will be able to move your actors around and change the speed, as is possible in Greenfoot itself.
Once you have filled in all the details, make sure you have entered your username and password and click the Export button to publish your scenario to the gallery. If you click Cancel then the details you have entered will be saved ready for when you do want to export it.
To export your scenario as a webpage, select the Webpage section in the export dialog box. Select a folder to save the webpage to, choose whether you want to lock the scenario or not, and click Export.
Checking the Lock scenario check box prevents users of your scenario from changing the speed of execution and dragging objects around the world before the scenario is run. If you uncheck this box then users will be able to move your actors around and change the speed, as is possible in Greenfoot itself.
Note that exporting the scenario as a webpage will not publish your scenario on the web, it will only allow you to view the scenario in a web browser. To publish the scenario to the web (if you do not have your own website) use the Publish section of the export dialog to publish the scenario to the Greenfoot gallery. To publish the scenario to your own website, export it as a webpage then upload the .html and .jar files to your web server.
To export your scenario as an application, select the Application section in the export dialog box. Select a folder to save the application to, choose whether you want to lock the scenario or not, and click Export.
Checking the Lock scenario check box prevents users of your scenario from changing the speed of execution and dragging objects around the world before the scenario is run. If you uncheck this box then users will be able to move your actors around and change the speed, as is possible in Greenfoot itself.
The application created will be an executable jar file. Any computer with the right version of Java installed should be able to run this application. On most computers you will be able to double-click on the jar file to run it. If the computer is not set up to run jar files like that, you will have to use the following command on a command-line to run the scenario:
java -jar Scenario.jar
While you are in the same folder as the jar file, replacing the name Scenario.jar with the name of your file.