Android Open Source - Layrd Layrd Sound






From Project

Back to project page Layrd.

License

The source code is released under:

MIT License

If you think the Android project Layrd listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Sound component which receives sound events form the Logic component and
 * then plays the sound effect.//from w w  w .java  2  s  .  c  o m
 * 
 * We need to generate a mapping or another way to store sounds and music as
 * they are loaded in the game. We then can use that mapping access the
 * generated sounds `eg Gdx.audio.newSound(Gdx.files.internal("mp3.mp3"));`
 * and play them directly.
 * 
 * Do not forget to dispose of the sounds as the game exits.
 */
package com.Voltronics.game;

import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;


public class LayrdSound {
  private static Map<String, Sound> soundManager = new HashMap<String, Sound>();
  private static Map<String, Sound> musicManager = new HashMap<String, Sound>();
  
  
  public static void loadSounds(String[] keys, String[] paths){
    for(int i = 0; i < paths.length; i++)
      loadSound(keys[i], paths[i]);
  }
  
  public static void loadSound(String key, String path){
    soundManager.put(key, Gdx.audio.newSound(Gdx.files.internal(path)));
  }
  
  
  public static Sound getSound(String soundName){
    if(soundManager.containsKey(soundName)){
      return soundManager.get(soundName);
    }
    
    return null;
  }
  
  
  public static void loadMusics(String[] keys, String[] paths){
    for(int i = 0; i < paths.length; i++)
      loadMusic(keys[i], paths[i]);
  }
  
  public static void loadMusic(String key, String path){
    musicManager.put(key, Gdx.audio.newSound(Gdx.files.internal(path)));
  }
  
  
  public static Sound getMusic(String soundName){
    if(musicManager.containsKey(soundName)){
      return musicManager.get(soundName);
    }
    
    // no sound found, return null?
    return null;
  }
  
  
  
}




Java Source Code List

com.Voltronics.game.GameObject.java
com.Voltronics.game.LayrdGame.java
com.Voltronics.game.LayrdGoogleGameInterface.java
com.Voltronics.game.LayrdGraphics.java
com.Voltronics.game.LayrdInput.java
com.Voltronics.game.LayrdLogic.java
com.Voltronics.game.LayrdPhysics.java
com.Voltronics.game.LayrdScreenGame.java
com.Voltronics.game.LayrdScreenMainMenu.java
com.Voltronics.game.LayrdSound.java
com.Voltronics.game.LayrdWorld.java
com.Voltronics.game.Player.java
com.Voltronics.game.TutorialScreen.java
com.Voltronics.game.android.AndroidLauncher.java
com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java