Playing sound from child of AudioNode?

I have an AudioNode in my project that contains all of the sounds for my game. I want to play an instance of a sound but I notice world.soundNode.getChild(0) doesn’t have a play/playinstance method. The getChild seems to treat the node as if it where a spatial.

I was curious if this was over looked or is there another way to access a group of Audio nodes with out creating an array of individual AudioNodes ?


Okay , so I found since I needed to loop through the node this would work instead.

for (AudioNode x : world.soundNode.descendantMatches(AudioNode.class, null)) {

Erm, a Node is a Spatial. You can cast it to Node if its really a Node.

To explain a bit further what normen said:
It’s simple, you have Spatials which are the “superior” class, from which e.g. Geometry and Nodes descend. From those Nodes, AudioNodes descend (See “The SceneGraph” in the Wiki)

It’s simple: You cast getChild(0) to AudioNode (but not always blindly rely on that:)

Spatial s = soundNode.getChild(0);
if (s instanceof AudioNode)
    AudioNode a = (AudioNode)s;

But: This sounds like a really poor design to me:
a) You can’t rely on the order of your Children (or it’s stupid to have an index)
b) If you’d do it like this, set the nodes Name and use .getChildren("") which even handles multiple levels:
Root → index 0 → index 0 would be
.(Node)(getChild(0)).getChild(0) (because you’d need to cast to Node and still then everything would crash if the children isn’t there.

The best thing would be to add the nodes for example to your player, so you can start them and have stereo sound.
I don’t know what happens if you add an AudioNode as a children to an AudioNode. I guess both would be played then.

If your goal was to play everything at once (as your snippet suggests), you could also have a LinkedList with all AudioNodes and simply iterate over them, add the nodes to the rootNode and play the AudioNodes.