Write a description of class Boat here. (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.io. GetWorld(). So basically the sound is a really short sound it only lasts about 3 seconds, but when I run it, the sound does not stop. If (buttonType = -2) // i.e., the stop button was pressed We're a playing a song that is NOT paused Here, we pressed the pause button and the song If (buttonType = -1) // i.e., was the pause button clicked? If we are here, the mouse button was clicked These occurrences will be located in the code of the control buttons when referring to the current selection. Then, you will need to make the appropriate changes within the code (like changing the appropriate occurences of 'buttonType' to 'songButton.buttonType' and change the appropriate 'gfs' occurrences to 'songButton.gfs', etc.). So, you will be removing the 'songPlaying' field altogether and replace it with a 'private static Button songButton' field. To make them accessible, however, either lines 8 and 9 need to be made 'public' instead of 'private' or public getter method will need to be added to the class to allow access to their values. This would be what is needed since you apparently need access to both those values. By holding the song button in a class field, its 'buttonType' and its 'gfs' will be available. What is left? - how about the Button itself. If you save the GreenfootSound object, you will not keep the song number. Maybe that field should be replaced with something a little more useful. A problem with acquiring that particular song is found when you realize that only the number of the song is available in the 'songPlaying' class field. So, calling 'gfs.stop()' or 'gfs.pause()' (see lines 43 and ? wherever it disappeared to ?) will not call the stop and pause methods on the song that is currently playing. GetWorld().showText("Starting song " + buttonType + " named " + song, 250, 380) Įach button created in your project is getting a 'gfs' field of its own - even the 'play', 'pause' and 'stop' buttons. GetWorld().showText("Button type: " + buttonType + ", song name: '" + song + "'", 250, 320) IsMouseClicked = Greenfoot.mouseClicked(this) I am not sure what you were trying to do with line 1 (or why you wanted to create a method here).Public Button(String imageName, String songName, int typeOfButton) 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. Method names should give some indication as to what the method does the first word in the name should be a verb. Your expression to the right of the equal sign on line 3 looks good. '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.). VariableType variableName = expression_or_value 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): wav files into a scenario, and methods let you play those sounds when specific events are triggered. I am having problems with music, I am putting it in the act file of an actor so it doesnt contantly play, but when I use an mp3 file, it lags and crashes, then when a try to use a.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |