![]() I am not sure what you were trying to do with line 1 (or why you wanted to create a method here). If you got 'GreenfootSound( filename)' from the API, then you were looking at the constructor signature and you used it properly at the end of line 3. The argument 'filename' is not used in the method anywhere - so there is no need to have the argument at all. Download Greenfoot for free: runs on Windows, Mac and Linux The Book Introduction to Programming with Greenfoot is the official book used by both teachers and students The Greenroom. Method names should give some indication as to what the method does the first word in the name should be a verb. Share 3.5K views 6 years ago Greenfoot tutorials Triggering a sound on an event, in this case a collision.more. Your expression to the right of the equal sign on line 3 looks good. Greenfoot provides a Greenfoot.getRandomNumber function that will give you a random number. 'variableName' can be any name that follows the rules given at the bottom of this page. 'variableType' can be any primitive type (int, float, boolean, long, byte, char, etc.) or a class name (String, Color, Font, Actor, World, etc.). The folder your scenario is in bears the name of your. That is where you paste the sound files for that project. Find the sounds folder and open it (it should be there and it should be empty). Add code that generates a random number and uses that to decide which leaf image to display. Notice that there are 4 possible images for leaves, even though right now, only one image is displayed. Right now, all it does is set a speed for the leaves. Perhaps you could string multiple copies of the sound together. this is exactly the problem: Take a look at the constructor. If there are still problems, Im afraid that they are issues with either your sound file or with Javas sound functionality, and theres not much you can do about it. ![]() ![]() We can make that sound play every time the crab eats a worm by adding a single line to our crab class that calls aySound after we remove a worm from the world: Give that a try. VariableType variableName = expression_or_value Find the folder for the project you are working on and open it. First, use the most recent version of Greenfoot (2.2.1), if youre not already. The scenario comes with a sound ready for you to use, named 'eating.wav'. Find information on how to change the interface language in Greenfoot, and get other translated materials. Greenfoot has been translated into many different languages. Neither line 3 nor line 4 could possibly compile without an exception being thrown.Ī variable is assigned a value like as in the following (in pseudo-code): For 32-bit support, use Greenfoot 3.5.4 from our old versions page. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |