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

2016/3/18

adding sound to a command line game

divinity divinity

2016/3/18

#
hi danpost this is jus a question, if yuh are building a command line game in java and yuh want to add sound like effect in it how do you go about doing it
danpost danpost

2016/3/18

#
divinity wrote...
if yuh are building a command line game in java and yuh want to add sound like effect in it how do you go about doing it
Please give an example of what you mean for clarification.
divinity divinity

2016/3/18

#
what i meant is if you are building a command line multiplication game, how do you add a sound to it
danpost danpost

2016/3/18

#
Again, be specific -- when would you want the sound to play? and are you talking about a program outside of greenfoot? or, are you going to create an executable jar file by way of greenfoot?
Randy. Randy.

2016/3/19

#
1
2
3
4
5
6
7
8
// This creates the music
GreenfootSound Sound = new GreenfootSound("songName.wav");
 
// This starts it (it's looped)
Sound.playLoop()
 
// And you can use this to stop it
Sound.stop();
danpost danpost

2016/3/19

#
The code Randy gave is more for background music or sounds that need to be controlled (usually sounds of some duration). Quick blurbs for when specific occurences happen can usually be played without setting up a reference to it:
1
Greenfoot.playSound("soundName.wav");
You need to login to post a reply.