Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package testaudio;
- import com.jme3.app.SimpleApplication;
- import com.jme3.asset.plugins.FileLocator;
- import com.jme3.audio.AudioNode;
- import com.jme3.input.controls.ActionListener;
- import com.jme3.input.controls.MouseButtonTrigger;
- import com.jme3.material.Material;
- import com.jme3.math.ColorRGBA;
- import com.jme3.math.Vector3f;
- import com.jme3.scene.Geometry;
- import com.jme3.scene.shape.Box;
- public class Testaudio extends SimpleApplication{
- private AudioNode soundpos1;
- private AudioNode soundpos2;
- private AudioNode soundpos3;
- private AudioNode soundnopos;
- private Geometry player;
- public static Testaudio app;
- int i = 0;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- app = new Testaudio();
- app.start();
- }
- @Override
- public void simpleInitApp() {
- flyCam.setMoveSpeed(40);
- /** just a blue box floating in space */
- Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
- player = new Geometry("Player", box1);
- Material mat1 = new Material(assetManager,
- "Common/MatDefs/Misc/Unshaded.j3md");
- mat1.setColor("Color", ColorRGBA.Blue);
- player.setMaterial(mat1);
- rootNode.attachChild(player);
- /** custom init methods, see below */
- initKeys();
- initAudio();
- }
- private void initAudio() {
- assetManager.registerLocator("C:/", FileLocator.class);
- soundpos1 = new AudioNode(assetManager, "ASSETS/SOUNDS/BGM/esismono.wav");
- soundpos1.setPositional(true);
- soundpos1.setMaxDistance(50f);
- soundpos1.setLocalTranslation(-200, 0, -200);
- soundpos1.setLooping(true);
- soundpos1.play();
- soundpos2 = new AudioNode(assetManager, "ASSETS/SOUNDS/BGM/gerudomono.wav");
- soundpos2.setPositional(true);
- soundpos2.setMaxDistance(50f);
- soundpos2.setLocalTranslation(-200, 0, -200);
- soundpos2.setLooping(true);
- soundpos2.play();
- soundnopos = new AudioNode(assetManager, "ASSETS/SOUNDS/BGM/dafthbfs.wav");
- soundnopos.setPositional(false);
- soundnopos.setVolume(0.3f);
- soundnopos.setLooping(true);
- soundnopos.play();
- }
- private void initKeys() {
- inputManager.addMapping("leftClick", new MouseButtonTrigger(0));
- inputManager.addMapping("rightClick", new MouseButtonTrigger(1));
- inputManager.addListener(actionListener, "leftClick");
- inputManager.addListener(actionListener, "rightClick");
- }
- private ActionListener actionListener = new ActionListener() {
- @Override
- public void onAction(String name, boolean keyPressed, float tpf) {
- if (name.equals("leftClick") && !keyPressed) {
- if (soundpos1 != null){
- soundpos1.stop();
- }
- }
- if (name.equals("rightClick") && !keyPressed) {
- if (soundpos2 != null){
- soundpos2.stop();
- }
- }
- }
- };
- @Override
- public void simpleUpdate(float tpf) {
- if (soundpos1.getStatus() == AudioNode.Status.Playing || soundpos2.getStatus() == AudioNode.Status.Playing){
- if (soundpos1.getLocalTranslation() == new Vector3f(-200,0,-200)){
- soundpos1.setLocalTranslation(new Vector3f(-200,0,200));
- soundpos2.setLocalTranslation(new Vector3f(-200,0,200));
- // soundMan.setSoundPosition(soundpos3, new Vector3f(-200,0,200));
- } else if (soundpos1.getLocalTranslation() == new Vector3f(-200,0,200)){
- soundpos1.setLocalTranslation(new Vector3f(200,0,200));
- soundpos2.setLocalTranslation(new Vector3f(200,0,200));
- // soundMan.setSoundPosition(soundpos3, new Vector3f(200,0,200));
- } else if (soundpos1.getLocalTranslation() == new Vector3f(200,0,200)){
- soundpos1.setLocalTranslation(new Vector3f(-200,0,200));
- soundpos2.setLocalTranslation(new Vector3f(-200,0,200));
- // soundMan.setSoundPosition(soundpos3, new Vector3f(-200,0,200));
- } else {
- soundpos1.setLocalTranslation(new Vector3f(-200,0,-200));
- soundpos2.setLocalTranslation(new Vector3f(-200,0,-200));
- // soundMan.setSoundPosition(soundpos3, new Vector3f(-200,0,-200));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment