Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Scenarios In Greenfoot. Greenfoot Scenarios are made up of: Greenfoot Scenarios are made up of: A World class. A World class. Actor classes.

Similar presentations


Presentation on theme: "Creating Scenarios In Greenfoot. Greenfoot Scenarios are made up of: Greenfoot Scenarios are made up of: A World class. A World class. Actor classes."— Presentation transcript:

1 Creating Scenarios In Greenfoot

2 Greenfoot Scenarios are made up of: Greenfoot Scenarios are made up of: A World class. A World class. Actor classes. Actor classes. To add these in a new scenario: To add these in a new scenario: Right click on the World class or Actor class Right click on the World class or Actor class Select “New Subclass” Select “New Subclass”

3

4 Select the background you want (for a World) or the icon your want (for an Actor) Select the background you want (for a World) or the icon your want (for an Actor)

5 Greenfoot Worlds are composed of a grid. Greenfoot Worlds are composed of a grid. Grids are composed of cells. For example, this grid is 3 cells by 4 cells. Grids are composed of cells. For example, this grid is 3 cells by 4 cells. The cells in Greenfoot are all square. The cells in Greenfoot are all square.

6 To define the properties of a World’s grid, you put the following in the World’s constructor: To define the properties of a World’s grid, you put the following in the World’s constructor: super(10, 5, 10); The World is 10 cells wide. The World is 5 cells high. Each cell is 10 pixels by 10 pixels.

7 super(10, 5, 10); super(10, 5, 10);

8 If your cells are really big, the animation for your actors will look choppy. The actors are going from one cell to the next. If your cells are really big, the animation for your actors will look choppy. The actors are going from one cell to the next.

9

10

11 The solution to get rid of the choppy animation is to shrink the cell size. The solution to get rid of the choppy animation is to shrink the cell size. super(10, 5, 1); The World is 10 cells wide. The World is 5 cells high. Each cell is 1 pixel by 1 pixel.

12 super(10, 5, 10); super(10, 5, 10); Notice that the world is now smaller because our cell size is smaller. We need to adjust the dimensions of the world to account for the smaller cell size.

13 Let’s double the width and height of the world’s cells: Let’s double the width and height of the world’s cells: super(20, 10, 1); super(20, 10, 1); The World is now 20 cells wide. The World is now 10 cells high. Each cell is 1 pixel by 1 pixel.

14 super(20, 10, 1); super(20, 10, 1);  Now our animation should be smoother.

15 super(20, 10, 1); super(20, 10, 1);  Now our animation should be smoother.

16 super(20, 10, 1); super(20, 10, 1);  Now our animation should be smoother.

17 The World subclass that you create has access to the World class’ methods. The World subclass that you create has access to the World class’ methods. One important method is addObject( ) One important method is addObject( ) addObject( ) addObject( ) To automatically create an Actor method in the world when your World class is initialized use this method. To automatically create an Actor method in the world when your World class is initialized use this method. Syntax: addObject(greenfoot.Actor object, int x, int y) Syntax: addObject(greenfoot.Actor object, int x, int y)addObject Ex: addObject(new Ladybug( ), 7, 3); Ex: addObject(new Ladybug( ), 7, 3);

18 addObject(new Ladybug( ), 7, 3);  The Ladybug will be created here. addObject(new Ladybug( ), 7, 3);  The Ladybug will be created here.  You have probably noticed that Java’s y axis starts at the top left!

19 The Actor subclass (Ladybug) that you create has access to the Actor class’ methods. The Actor subclass (Ladybug) that you create has access to the Actor class’ methods. One important method is setLocation( ) One important method is setLocation( ) setLocation( ) setLocation( ) To send an Actor object to a location in the grid you use this method. To send an Actor object to a location in the grid you use this method. Syntax: setLocation(int x, int y) Syntax: setLocation(int x, int y)setLocation Ex: setLocation(2, 4); Ex: setLocation(2, 4);

20 setLocation(2, 4);  The Ladybug will be sent here. setLocation(2, 4);  The Ladybug will be sent here.

21 The Actor class also has “get axis” methods that return the location of the object. The Actor class also has “get axis” methods that return the location of the object. getX( ) getX( ) getY( ) getY( ) To make the Actor object move forward use these methods with the setLocation method inside the Act method: To make the Actor object move forward use these methods with the setLocation method inside the Act method: Ex: setLocation(getX( ) + 1, getY( )); Ex: setLocation(getX( ) + 1, getY( ));


Download ppt "Creating Scenarios In Greenfoot. Greenfoot Scenarios are made up of: Greenfoot Scenarios are made up of: A World class. A World class. Actor classes."

Similar presentations


Ads by Google