3/18/2024 0 Comments Greenfoot loop sound![]() ![]() When the mouse is click on this object, play the sound. * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Emoticon wants to do. Try re-saving the sound file withouth them and try again. Use the method setImage( filename ) to set the image.Įmoticon emoticon = new Emoticon(image ,sound ) There are probably information tags in the mp3 file that Greenfoot/Java does not like. 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 * Note: concatinate the ".png" for images and ".wav" for the sounds * 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) With the last one, the Bts object is not being removed - nor is a different world being set active. Create a new world with 400x100 cells with a cell size of 1x1 pixels. You should note that all other sounds are triggered by objects that are immediately being removed from the world. * Constructor for objects of class HomeworkWorld. * Create two instance varaibles of type String Then you can start and stop the sound like this: sound.start () //start playing the sound sound. * Write a description of class Emoticon here. You may want to check out other pages within the tutorial by selecting them from the list on the left side of the window.Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) To gain more control over the music, you must create and retain a GreenfootSound object in a field so you can call methods of the. It will only stop when you re-compile or leave the app. Please refer to Java tutorial page on Passing arguments to methods and constructors for more detailed information. If you are using aySound ('Theme1.mp3') to start the music, then because you do not retain a reference to the sound, you cannot stop it. Having them in the "( )" informs the compiler as to how many variables and of what type are to be passed when using that construct. The sound cannot be played several times simultaneously, but can be played several times sequentially. The two String objects, 'keyName' and 'soundFile', must be declared as parameters to the constructor call in order for those values to be passed from your world object to the Key object being created. A GreenfootSound loads the audio from a file. The Key object being created needs to save those values in its fields ('key' and 'sound') so that it can use them later (after the Key object is added into the world). The argument values brought into the constructor ('keyName' and 'soundFile') are only local variables (only the constructor is aware of them). The world does not need to know when these events occur only the Key objects do. Another check will look for the key to NOT be down and reset the 'isDown' field back to false. It will at the same time set the 'isDown' field to true. You should have an 'act' method that will check for the key stored in the 'key' field and play the sound stored in the 'sound' field if that key is down. There should be more to the Key class than what you are showing. Use your Greenfoot knowldege: If an Actor class Fly has a variable defined to store the current speed, which of the following statements would successfully add a Fly and define the current speed as 2 Mark for Review. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |