This site requires JavaScript, please enable it in your browser!
Greenfoot back
liverpoolfc
liverpoolfc wrote ...

2019/7/24

sound

liverpoolfc liverpoolfc

2019/7/24

#
Can we loop the sound so that it repeats again till the game ends?
danpost danpost

2019/7/24

#
liverpoolfc wrote...
Can we loop the sound so that it repeats again till the game ends?
Only if you specifically create a GreenfootSound object. Then you can use the playLoop method.
liverpoolfc liverpoolfc

2019/7/24

#
How can you do this? Can you be more specific and clear? I am just a beginner and so I dont understand when you say those big computer words. Can you please explain it more simply?
danpost danpost

2019/7/24

#
liverpoolfc wrote...
I am just a beginner and so I dont understand when you say those big computer words.
The only "computer" word I used was method and you should know what that is. The other words you may not "know" are GreenfootSound (a class name) and playLoop (a method name). The class is provided by greenfoot and the method is in that class.
How can you do this? Can you be more specific and clear? Can you please explain it more simply?
You create an object and give it a name using the format: ObjectType name = new ObjectType(); As an example:
Counter counter = new Counter();
The right side creates a new Counter object. This object is then assigned to a variable called counter which, by the initializing Counter, is a new variable defined to only contain a Counter object. Instead of using something like the following:
Greenfoot.playSound("bgmusic.mp3");
you would use something like this:
GreenfootSound bgMusic = new GreenfootSound("bgmusic.mp3");
bgMusic.playLoop();
liverpoolfc liverpoolfc

2019/7/25

#
oh I understand but does mp3 work?
liverpoolfc liverpoolfc

2019/7/25

#
Can we also reduce the volume for some sounds and increse the volume for some sounds.
danpost danpost

2019/7/25

#
liverpoolfc wrote...
oh I understand but does mp3 work?
Greenfoot has supported mp3 for quite some time.
liverpoolfc wrote...
Can we also reduce the volume for some sounds and increse the volume for some sounds.
Please refer to the GreenfootSound API documentation to see what methods are available.
liverpoolfc liverpoolfc

2019/7/25

#
Can we also make the sound start only after the run button is pressed?
liverpoolfc liverpoolfc

2019/7/25

#
I also have another problem. I have many sounds that will play during a specific time but during the time my player shoots a sound is played but playing of that sound delays the entire program. Can you help me fix this?
danpost danpost

2019/7/25

#
liverpoolfc wrote...
Can we also make the sound start only after the run button is pressed?
Use the World class started method.
liverpoolfc wrote...
I also have another problem. I have many sounds that will play during a specific time but during the time my player shoots a sound is played but playing of that sound delays the entire program. Can you help me fix this?
There is not much you can do if the sound can be played over itself (if one instance of the sound may not end before another instance of it starrts). If no instance of. it overlaps another, then you can place the GreenfootSound object in a static field. That way, the file read in once before being needed and does not have to be read each time the sound is played.
liverpoolfc liverpoolfc

2019/7/25

#
How do you use started method?
liverpoolfc liverpoolfc

2019/7/25

#
How do you make it in a static field
liverpoolfc liverpoolfc

2019/7/25

#
I tried referring the GreenfootAPI documentation but still I didnt understand. So can you explain it please?
Super_Hippo Super_Hippo

2019/7/25

#
public void started()
{
    bgMusic.playLoop();
}

public void stopped()
{
    bgMusic.pause();
}
You need to login to post a reply.