Procházet zdrojové kódy

Wiki refresh (Hello Audio) (#160)

I am going through the beginner wiki pages and updating them so they are the same as the source code files in jme3test/helloworld.

In this we update the AudioNode audio_nature, private Geometry player, and the ActionListener lines

jme3test/helloworld source code:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/helloworld/HelloAudio.java
woodx319 před 3 roky
rodič
revize
d0652bd845

+ 8 - 11
docs/modules/tutorials/pages/beginner/hello_audio.adoc

@@ -30,8 +30,6 @@ import com.jme3.scene.shape.Box;
 public class HelloAudio extends SimpleApplication {
 
   private AudioNode audio_gun;
-  private AudioNode audio_nature;
-  private Geometry player;
 
   public static void main(String[] args) {
     HelloAudio app = new HelloAudio();
@@ -44,7 +42,7 @@ public class HelloAudio extends SimpleApplication {
 
     /** just a blue box floating in space */
     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");
     mat1.setColor("Color", ColorRGBA.Blue);
     player.setMaterial(mat1);
@@ -65,7 +63,7 @@ public class HelloAudio extends SimpleApplication {
     rootNode.attachChild(audio_gun);
 
     /* 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.setPositional(true);
     audio_nature.setVolume(3);
@@ -80,7 +78,7 @@ public class HelloAudio extends SimpleApplication {
   }
 
   /** Defining the "Shoot" action: Play a gun sound. */
-  private ActionListener actionListener = new ActionListener() {
+  final private ActionListener actionListener = new ActionListener() {
     @Override
     public void onAction(String name, boolean keyPressed, float tpf) {
       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_nature;
-
+  
 ----
 
 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_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. */
-  private ActionListener actionListener = new ActionListener() {
+  final private ActionListener actionListener = new ActionListener() {
     @Override
     public void onAction(String name, boolean keyPressed, float tpf) {
       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. */
-  private ActionListener actionListener = new ActionListener() {
+  final private ActionListener actionListener = new ActionListener() {
     @Override
     public void onAction(String name, boolean keyPressed, float tpf) {
       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_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.