Local Sprites
TourSprite
offers a simplified interface for moving and rotating a local sprite. It communicates movements, rotations, and its initial creation to the server. The complete class appears in Example 32-1.
Example 32-1. The TourSprite class
public class TourSprite extends Sprite3D { private final static double MOVERATE = 0.3; private final static double ROTATE_AMT = Math.PI / 16.0; PrintWriter out; // for sending commands to the server public TourSprite(String userName, String fnm, Obstacles obs, double xPosn, double zPosn, PrintWriter o) { super(userName, fnm, obs); setPosition(xPosn, zPosn); out = o; out.println("create " + userName + " " + xPosn + " " + zPosn); } // moves public boolean moveForward() { out.println("forward"); return moveBy(0.0, MOVERATE); } public boolean moveBackward() { out.println("back"); return moveBy(0.0, -MOVERATE); } public boolean moveLeft() { out.println("left"); return moveBy(-MOVERATE,0.0); } public boolean moveRight() { out.println("right"); return moveBy(MOVERATE,0.0); } // rotations in Y-axis only public void rotClock() { out.println("rotClock"); doRotateY(-ROTATE_AMT); // clockwise } public void rotCounterClock() { out.println("rotCClock"); doRotateY(ROTATE_AMT); // counter-clockwise } } // end of TourSprite
Creating a Local Sprite
WrapNetTour3D
creates a local sprite by invoking a TourSprite
object and adding it to the scene graph. As part of TourSprite
's construction, a create n x z
message is sent to the server; n
is its client's ...
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.