Sprite3D is the base class for creating 3D sprites. The
TourSprite subclass is used to create the user's robot sprite, and
AlienSprite is a subclass of
TourSprite for the alien hand.
TourSprite is controlled by
TouristControls, which monitors user key presses and can adjust the sprite's position or the user's viewpoint as needed.
AlienSprite is periodically updated by the
class to make the alien hand chase the user's sprite.
Figure 18-6 shows the public methods of the
Behavior classes and the relationships between them.
Figure 18-6. Sprite3D and Behavior classes
Sprite3D represents a model able to move about the XZ plane, rotate around the y-axis, and detect obstacles and floor boundaries. The sprite can be made inactive, which will cause it to disappear from the scene.
The constructor for
PropManager to load the model representing the sprite. It then adds a
Switch node and
TransformGroup above the model's graph. The result can be seen in the branches for the robot (Coolrobo.3ds) and alien hand (hand1.obj) in Figure 18-4. Here is the relevant code:
PropManager propMan = new PropManager(fnm, true); visSwitch = new Switch(); // for sprite visibility visSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); visSwitch.addChild( propMan.getTG() ); // add obj to switch visSwitch.setWhichChild( Switch.CHILD_ALL ); // make visible ...