コード例 #1
0
 public void startBackgroundMusic() {
   String backgroundTrack =
       "/sound/Background " + (TurnSynchronizer.synchedRandom.nextInt(4) + 1) + ".ogg";
   if (!isMuted() && hasOggPlaybackSupport() && !isPlaying(BACKGROUND_TRACK)) {
     soundSystem.backgroundMusic(
         BACKGROUND_TRACK, SoundPlayer.class.getResource(backgroundTrack), backgroundTrack, true);
   }
 }
コード例 #2
0
  private boolean playSound(String sourceName, float x, float y, boolean blocking, int index) {
    if (index < MAX_SOURCES_PER_SOUND && !isMuted() && hasWavPlaybackSupport()) {
      String indexedSourceName = sourceName + index;
      if (!loaded.contains(indexedSourceName)) {
        soundSystem.newSource(
            false,
            indexedSourceName,
            SoundPlayer.class.getResource(sourceName),
            sourceName,
            false,
            x,
            y,
            0,
            SoundSystemConfig.ATTENUATION_ROLLOFF,
            SoundSystemConfig.getDefaultRolloff());
        loaded.add(indexedSourceName);
      } else if (isPlaying(indexedSourceName)) {
        if (blocking) {
          return false;
        }

        // Source already playing, create new source for same sound
        // effect.
        return playSound(sourceName, x, y, false, index + 1);
      }
      soundSystem.stop(indexedSourceName);
      soundSystem.setPriority(indexedSourceName, false);
      soundSystem.setPosition(indexedSourceName, x, y, 0);
      soundSystem.setAttenuation(indexedSourceName, SoundSystemConfig.ATTENUATION_ROLLOFF);
      soundSystem.setDistOrRoll(indexedSourceName, SoundSystemConfig.getDefaultRolloff());
      soundSystem.setPitch(indexedSourceName, 1.0f);
      soundSystem.play(indexedSourceName);
      return true;
    }
    return false;
  }
コード例 #3
0
 public void setListenerPosition(float x, float y) {
   soundSystem.setListenerPosition(x, y, 50);
 }
コード例 #4
0
 public void stopBackgroundMusic() {
   if (hasOggPlaybackSupport()) {
     soundSystem.stop(BACKGROUND_TRACK);
   }
 }
コード例 #5
0
 private boolean isPlaying(String sourceName) {
   if (hasOggPlaybackSupport()) {
     return soundSystem.playing(sourceName);
   }
   return false;
 }
コード例 #6
0
 public void shutdown() {
   if (soundSystem != null) {
     soundSystem.cleanup();
   }
 }