3 Using the API When programming with Greenfoot, it is essential to know about the methods available in the standard Greenfoot classes. On the Grenfoot website there is a tutorial video available that shows how to create and set up a new scenario. That's what we'll start in the next section. In other words: we have to define our own world, and then we have to define one or more of our own actors. In order to progress from here, we need to create subclasses (that is: special cases) of World and of Actor. As a result, even if we had an actor object now, we could not place it anywhere, because we cannot create a world. Especially, there is no world object at the moment, because we have no finished world class to make a world object from. Both 'World' and 'Actor' are abstract classes - that is: you cannot create any objects of them. That is: you have the 'World' and 'Actor' classes in the class display, and not much else. The scenario will be opened, and you will see a screen similar to the one on the left. Greenfoot will create a folder with that name that contains all files associated with your scenario. Doing this is easy: choose 'New' from the 'Scenario' menu, and select a location and name for your scenario. Have fun! 2 Creating a new scenario The first thing to do when you want to create your own program is to create your own scenario. You can find them in the 'scenarios' folder. All these scenarios are included in the standard Greenfoot distribution. Every now and then, when it is useful to refer to examples, we will use the 'wombats', 'ants', 'balloons' and 'lunarlander' scenarios as examples. 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. You may, for instance, be interested in generating actor images in a certain way, or in dealing with collisions. Feel free to jump right into the middle of this manual and start reading there. In that case, you already have a scenario, a world, and one or more actor classes. In fact, probably the most common way for people to start programming in Greenfoot is by modifying an existing scenario. This may not be the order in which you approach your own personal Greenfoot programming experience. It starts from the start: We first discuss how to create a new scenario, then how to create worlds and actors, and so on. For tutorials, videos and a quickstart guide for Greenfoot, see the 'Getting Started' section on This manual is an introduction to programming in Greenfoot. It supports development of graphical applications in the JavaTM Programming Language. 1 Introduction Creating a new scenario Using the API Creating a world Creating new actors Making things move Random behavious Dealing with images Detecting other objects (collisions) Keyboard input Mouse input Playing audio Controlling the scenario Using support classes Exporting a scenario Introduction Greenfoot is a software tool designed to let beginners get experience with object-oriented programming. The Greenfoot Programmers' Manual Version 1.1 for Greenfoot 2.0 Michael Kölling, Martin Pain University of Kent Copyright © M Kölling, 2006, 2009, 2010 The Greenfoot Programmers' Manual is licensed under a Creative Commons Attribution-Non-Commercial 2.0 UK: England & Wales License.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |