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. You need to get a reference to the GreenfootSound object already playing to stop it. Method names should give some indication as to what the method does the first word in the name should be a verb. In your second code snippet, you are creating a new StartButton object, which creates an entirely new instance of the GreenfootSound object which is not yet playing so, stopping that sound will do nothing. Your expression to the right of the equal sign on line 3 looks good. But, it does know about an 'isTouching' method for an Actor object. Nor does it know of any 'Touching' method (even if 'is' referred to an Actor object). STRINGLENGTHLIMIT - Static variable in class greenfoot.UserInfo. The compiler does not know what object 'is' refers to. store() - Method in class greenfoot.UserInfo. This method is called by the Greenfoot system when the execution has stopped. stopped() - Method in class greenfoot.World. 'variableName' can be any name that follows the rules given at the bottom of this page. Stop playing this sound if it is currently playing. 'variableType' can be any primitive type (int, float, boolean, long, byte, char, etc.) or a class name (String, Color, Font, Actor, World, etc.). By now youre probably tired of always having to add new objects to the world every time we compile the code. This tutorial will explain how to initialise the world with actors, as well as how to play and record sounds. The resources for the sound will not be released while it is paused. Then you can start and stop the sound like this: sound.start () //start playing the sound sound. If you dont have any SFX/music, look on itch.io for some free SFX To implement it in your game you need to use aySound('example. If possible, you should always use stop(), because the resources can be released after calling stop(). So basically, you need to get a recording of your sound and then put it in the sounds folder of your greenfoot project. Make sure that this is really the method you want. VariableType variableName = expression_or_value Tutorial 4: Saving the World, Making and Playing Sound. If the sound is played again later, it will resume from the point where it was paused. One way is to use the Greenfoot class method 'playSound' the other is to actually create a GreenfootSound object and use the methods provided in the GreenfootSound class to control it. 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): It can be a bit confusing - especially because there are two different ways to have music play within greenfoot. Is playing: falseĪt (GreenfootUtil.java:532)Īt (SoundFactory.That could not possibly compile. Is playing: falseĪt (SoundExceptionHandler.java:66)Īt (SoundFactory.java:115)Īt (SoundFactory.java:130)Īt (Greenfoot.java:163)Īt Asteroids.check_hit(Asteroids.java:48)Īt (Simulation.java:507)Īt (Simulation.java:470)Īt (Simulation.java:204)Īt (Simulation.java:194)Ĭaused by: java.io.FileNotFoundException: Could not find file: file: break.mp3. : Could not open sound file: file: break.mp3. GetWorld().addObject(new Asteroids(size/2, Greenfoot.getRandomNumber(3) + 1, Greenfoot.getRandomNumber(45) + 45, Greenfoot.getRandomNumber(360)), getX(), getY()) First, use the most recent version of Greenfoot (2.2.1), if youre not already. Schüler/innen programmieren ein einfaches Froggerspiel und üben grundlegende Greenfoot-/Programmiertechniken. If(split.isPlaying()) aySound("" + split) Featured Resources: A collection of different images, ordered by topic. Public Asteroids(int size, int move, int direction, int rotation) GreenfootSound split = new GreenfootSound("break.mp3")
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |