![]() You could probably eliminate either the 'soundFiles' or the 'songNames' array and use the same data for both creating the sound objects and displaying their names. It seems a bit redundant to have two arrays with exactly the same data. But, the above should get your fields (which I renamed to more properly fit what they represent) and their references set up properly. I am quite sure that things will need to be tended to there as well. wav files as audios but i aint a expert so pls. If the problem persists, indicate so and give more information as to what system type, java version and greenfoot version you are using. Maybe try mp3 format without identification tags included. This also does not presume that the rest of the class is fine and correct. First, try using a sound file editor to re-save the files. I presumes that your sound files are ".mp3" files - if not, you need to make the necessary correction. ![]() If(!selected & Greenfoot.mouseClicked(this)) This shows the adjustments to the beginning of your class. If you try 'pew. Public PlayMusicButton(String soundFiles, String songNames, Color colors) if an object hits an other object it must play 1 of the 3 sounds randomly. GreenfootSound pew new GreenfootSound ('pew.wav') This line creates one, and only one, instance of the sound. * Use the method aySound( class PlayMusicButton extends Actor What you need to do is tell it to play once. ![]() I may be wrong, but it seems to me that your problem is that you keep indefinitely call play() in an act method somewhere (Im guessing in your world). When the mouse is click on this object, play the sound. There is also a play() method (which I think you already knew) which will play the sound. * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Emoticon wants to do. Use the method setImage( filename ) to set the image.Įmoticon emoticon = new Emoticon(image ,sound ) set the instance variable sound to the value passed by the corresponding parameter 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. set the instance variable image to the value passed by the corresponding parameter The scenario comes with a sound ready for you to use, named 'eating.wav'. Sounds =new String("hello","happy","crying","ohno","raspberry") ĪddObject(new Emoticon(images, sound ), 70*(i+1), 50) Images =new String("smiley1", "smiley2", "smile圓", "smiley4", "smiley5") * The y value can be either hard coded or calculated * Determine the x value using a mathematical calculation So I set the sound on and press on play: my level 1 is loaded with the sound still playing. When i click on it the sound plays, if i press again the sour go off. ![]() * Note: concatinate the ".png" for images and ".wav" for the sounds I try to explain more clearly I got two world: one is the menu of my game the other is the level in which my game evolves. * It should use the method addObject( Actor object, int x, int y) to add new Emoticons to your world. * It should loop 5 times (you can either hard code 5 or use code) Create a new world with 400x100 cells with a cell size of 1x1 pixels. * Constructor for objects of class HomeworkWorld. I am working on a simple car game on greenfoot and I wanna add an alert sound if my car is getting closer to a truck. * Create two instance varaibles of type String * Write a description of class Emoticon here. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |