The explosion is best explained by considering the subgraph created inside
ExplosionsClip (see Figure 23-8).
The visual component of the explosion is implemented as a series of transparent GIF images, drawn one after another onto the surface of a
explTG is utilized to position the explosion shape at the point where the user clicked the mouse and to rotate it around the y-axis to face the user's viewpoint. The
Switch node is used to hide the explosion until needed.
The explosion sound is the
showExplosion() method positions it at the intercept point and then enables it (plays it).
The original design for the explosion had the
PointSound attached to the
explTG TransformGroup, which meant that would automatically move as the
Figure 23-8. Scenegraph branch for ExplosionsClip
moved. Unfortunately, a runtime exception rose as the sound was enabled, making this approach impossible. After some testing, I discovered the exception was caused by the
PointSound object being attached below the
explSwitch. This attachment should be possible; the exception is a bug in Java 3D 1.3.1.
I coded around the problem by moving the
PointSound node to a different branch from the
Switch node (as shown in Figure 23-8). This avoids the exception but means that the sound node must be explicitly translated to stay ...