public class Sound
extends java.lang.Object
A Sound is a sound effect. Like Sprites, SpriteSheets, and Music tracks, Sounds can be manually loaded and unloaded into and out of memory. Loading may take a moment, but while a Sound is not loaded, it cannot play.
Constructor and Description |
---|
Sound(java.lang.String path,
boolean load)
Creates a new Sound from an audio file.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isLoaded()
Returns whether this Sound is loaded.
|
boolean |
isPlaying()
Returns whether this Sound is currently playing.
|
boolean |
load()
Loads this Sound if it is not already loaded.
|
void |
loop()
Loops this Sound indefinitely.
|
void |
loop(double pitch,
double volume)
Loops this Sound indefinitely at the specified pitch and volume.
|
void |
play()
Plays this Sound once.
|
void |
play(double pitch,
double volume)
Plays this Sound once at the specified pitch and volume.
|
void |
stop()
Stops this Sound.
|
boolean |
unload()
Unloads this Sound if it is currently loaded.
|
public Sound(java.lang.String path, boolean load) throws org.newdawn.slick.SlickException
path
- The relative path to the audio fileload
- Whether this Sound should load upon creationorg.newdawn.slick.SlickException
- If the Sound could not be properly loaded from the
specified pathpublic final boolean isLoaded()
public final boolean load() throws org.newdawn.slick.SlickException
org.newdawn.slick.SlickException
- If the Sound could not be properly loadedpublic final boolean unload()
public final boolean isPlaying()
public final void play()
public final void play(double pitch, double volume)
pitch
- The pitch at which to play this Sound, with 1 representing
no pitch changevolume
- The volume at which to play this Sound, with 1 representing
no volume changepublic final void loop()
public final void loop(double pitch, double volume)
pitch
- The pitch at which to play this Sound, with 1 representing
no pitch changevolume
- The volume at which to play this Sound, with 1 representing
no volume changepublic final void stop()