|
@@ -30,8 +30,6 @@ import com.jme3.scene.shape.Box;
|
|
public class HelloAudio extends SimpleApplication {
|
|
public class HelloAudio extends SimpleApplication {
|
|
|
|
|
|
private AudioNode audio_gun;
|
|
private AudioNode audio_gun;
|
|
- private AudioNode audio_nature;
|
|
|
|
- private Geometry player;
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
HelloAudio app = new HelloAudio();
|
|
HelloAudio app = new HelloAudio();
|
|
@@ -44,7 +42,7 @@ public class HelloAudio extends SimpleApplication {
|
|
|
|
|
|
/** just a blue box floating in space */
|
|
/** just a blue box floating in space */
|
|
Box box1 = new Box(1, 1, 1);
|
|
Box box1 = new Box(1, 1, 1);
|
|
- player = new Geometry("Player", box1);
|
|
|
|
|
|
+ Geometry player = new Geometry("Player", box1);
|
|
Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
|
|
Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
|
|
mat1.setColor("Color", ColorRGBA.Blue);
|
|
mat1.setColor("Color", ColorRGBA.Blue);
|
|
player.setMaterial(mat1);
|
|
player.setMaterial(mat1);
|
|
@@ -65,7 +63,7 @@ public class HelloAudio extends SimpleApplication {
|
|
rootNode.attachChild(audio_gun);
|
|
rootNode.attachChild(audio_gun);
|
|
|
|
|
|
/* nature sound - keeps playing in a loop. */
|
|
/* nature sound - keeps playing in a loop. */
|
|
- audio_nature = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", DataType.Stream);
|
|
|
|
|
|
+ AudioNode audio_nature = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", DataType.Stream);
|
|
audio_nature.setLooping(true); // activate continuous playing
|
|
audio_nature.setLooping(true); // activate continuous playing
|
|
audio_nature.setPositional(true);
|
|
audio_nature.setPositional(true);
|
|
audio_nature.setVolume(3);
|
|
audio_nature.setVolume(3);
|
|
@@ -80,7 +78,7 @@ public class HelloAudio extends SimpleApplication {
|
|
}
|
|
}
|
|
|
|
|
|
/** Defining the "Shoot" action: Play a gun sound. */
|
|
/** Defining the "Shoot" action: Play a gun sound. */
|
|
- private ActionListener actionListener = new ActionListener() {
|
|
|
|
|
|
+ final private ActionListener actionListener = new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
if (name.equals("Shoot") && !keyPressed) {
|
|
if (name.equals("Shoot") && !keyPressed) {
|
|
@@ -120,8 +118,7 @@ For each sound, you create an AudioNode. You can use an AudioNode like any node
|
|
----
|
|
----
|
|
|
|
|
|
private AudioNode audio_gun;
|
|
private AudioNode audio_gun;
|
|
- private AudioNode audio_nature;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
----
|
|
----
|
|
|
|
|
|
Look at the custom `initAudio()` method: Here you initialize the sound objects and set their parameters.
|
|
Look at the custom `initAudio()` method: Here you initialize the sound objects and set their parameters.
|
|
@@ -131,7 +128,7 @@ Look at the custom `initAudio()` method: Here you initialize the sound objects a
|
|
|
|
|
|
audio_gun = new AudioNode(assetManager, "Sound/Effects/Gun.wav", DataType.Buffer);
|
|
audio_gun = new AudioNode(assetManager, "Sound/Effects/Gun.wav", DataType.Buffer);
|
|
...
|
|
...
|
|
-audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", DataType.Stream);
|
|
|
|
|
|
+AudioNode audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", DataType.Stream);
|
|
|
|
|
|
----
|
|
----
|
|
|
|
|
|
@@ -213,7 +210,7 @@ Setting up the ActionListener should also be familiar from previous tutorials. Y
|
|
----
|
|
----
|
|
|
|
|
|
/** Defining the "Shoot" action: Play a gun sound. */
|
|
/** Defining the "Shoot" action: Play a gun sound. */
|
|
- private ActionListener actionListener = new ActionListener() {
|
|
|
|
|
|
+ final private ActionListener actionListener = new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
if (name.equals("Shoot") && !keyPressed) {
|
|
if (name.equals("Shoot") && !keyPressed) {
|
|
@@ -253,7 +250,7 @@ Apart from the looping boolean, another difference is where `play().playInstance
|
|
----
|
|
----
|
|
|
|
|
|
/** Defining the "Shoot" action: Play a gun sound. */
|
|
/** Defining the "Shoot" action: Play a gun sound. */
|
|
- private ActionListener actionListener = new ActionListener() {
|
|
|
|
|
|
+ final private ActionListener actionListener = new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
if (name.equals("Shoot") && !keyPressed) {
|
|
if (name.equals("Shoot") && !keyPressed) {
|
|
@@ -273,7 +270,7 @@ The Enum in the AudioNode constructor defines whether the audio is buffered or s
|
|
----
|
|
----
|
|
audio_gunshot = new AudioNode(assetManager, "Sound/Effects/Gun.wav", DataType.Buffer); // buffered
|
|
audio_gunshot = new AudioNode(assetManager, "Sound/Effects/Gun.wav", DataType.Buffer); // buffered
|
|
...
|
|
...
|
|
-audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", DataType.Stream); // streamed
|
|
|
|
|
|
+AudioNode audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", DataType.Stream); // streamed
|
|
----
|
|
----
|
|
|
|
|
|
Typically, you stream long sounds, and buffer short sounds.
|
|
Typically, you stream long sounds, and buffer short sounds.
|