First you create a new sound like this: GreenfootSound sound new GreenfootSound ('filename') // the filename is the same as the one you would use in the playSound method You should create this sound as a global one (at the top of your code). ![]() Background music also starts when it runs and continues as the game plays. Its possible the tags could be causing it - I re-encoded the tracks into mp3 using audacity / lame and in my particular case that seemed to solve it. I have a subclass of world that is my start page and it switches to the game world (called 'MyWorld') when the user hits the space button. Then you can start and stop the sound like this: sound.start () //start playing the sound sound.stop () //stop playing the sound ayLoop () //plays the sound over and over again //also you can use any other mehtod from the GreenfootSound class AceticAcid. I'm not sure if I did something wrong with my sound file, or it's something else. If you want the sound to stop you have to use the class GreenfootSound. Ive seen this issue before, I believe its a bug in the JLayer mp3 library Greenfoot uses rather than with Greenfoot itself, and to that end theres not an awful lot we can do about it. You should create this sound as a global one (at the top of your code). Better is to create and keep a reference to a GreenfootSound object which you can control. With that, however, you have no control over it - it will play until completed (unless you close the project outright). just copy all your sound files into the folder sounds in your project folder, then you can use them in your code with aySound ('sound.mp3') or ayLoop () if song is an GreenfootSound. The UserInfo class can be used to store data permanently on a server, and to share this data between different users, when the scenario runs on the Greenfoot web site. This class contains information about the current status of the mouse. You will have to copy/paste them into the sounds directory of your project. Represents audio that can be played in Greenfoot. I was working on a new game, when I got this exception:Įxception in thread "SoundStream:file:/E:/Gebruikers/Sven/Programmeren/Greenfoot/Wolfenstein/sounds/backgroundSongs/backgroundSong1.MP3" : 580Īt javazoom.jl._decode(LayerIIIDecoder.java:795)Īt javazoom.jl.(LayerIIIDecoder.java:278)Īt javazoom.jl.(LayerIIIDecoder.java:219)Īt javazoom.jl.(Decoder.java:147)Īt (Mp3AudioInputStream.java:230)Īt (SoundStream.java:302) The simplest way is to use aySound ( / string filename of music file / ). Though, you could also shorten the code you currently have to: int position Greenfoot.getRandomNumber (3) addObject (new Grunt (), 125 +position125, 175) But the problem with your code currently is that it is placed in the worlds constructor, which only gets executed once (when the world is created). Greenfoot does not have an import function for sound files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |