1 / 21

Creating Scenarios In Greenfoot

Creating Scenarios In Greenfoot. Greenfoot Scenarios are made up of: A World class. Actor classes. To add these in a new scenario: Right click on the World class or Actor class Select “New Subclass”. Select the background you want (for a World) or the icon your want (for an Actor).

Download Presentation

Creating Scenarios In Greenfoot

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating ScenariosInGreenfoot

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

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

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

  5. 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.

  6. super(10, 5, 10);

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

  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.

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

  10. 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.

  11. 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.

  12. Let’s double the width and height of the world’s cells: 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.

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

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

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

  16. The World subclass that you create has access to the World class’ methods. • One important method is addObject( ) • addObject( ) • 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) • Ex: addObject(new Ladybug( ), 7, 3);

  17. 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!

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

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

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

More Related