3/20/2024 0 Comments Greenfoot sound stopThen, 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) Public Button(String imageName, String songName, int typeOfButton)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |