Causing an Explosion
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 QuadArray
inside explShape
. 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 PointSound
node, explPS
. 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 explShape
node
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 Switch
node, 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 ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.