Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Scene Creation on the Client

createSceneGraph() starts the main tasks of WrapNetTour3D: the 3D scene is created, contact is made with the server, and a local sprite is initialized:

    void createSceneGraph(String userName, String tourFnm,
                                           double xPosn, double zPosn)
    { sceneBG = new BranchGroup();
      bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);

      // allow clients to be added/removed from the world at run time
      sceneBG.setCapability(Group.ALLOW_CHILDREN_READ);
      sceneBG.setCapability(Group.ALLOW_CHILDREN_WRITE);
      sceneBG.setCapability(Group.ALLOW_CHILDREN_EXTEND);

      lightScene();         // add the lights
      addBackground();      // add the sky
      sceneBG.addChild( new CheckerFloor().getBG() );  // add the floor

      makeScenery(tourFnm);      // add scenery and obstacles

      makeContact(); // contact server (after Obstacles object created)

      addTourist(userName, xPosn, zPosn);
                     // add the user-controlled 3D sprite
      sceneBG.compile();   // fix the scene
    }

Capability bits are set to allow distributed sprites to be added to and removed from the scene at runtime.

makeContact() sets up an input and output stream to the server and passes the input stream to TourWatcher to monitor. TourWatcher creates distributed sprites when requested by the server, and so must know about the obstacles present in the world:

 private void makeContact() { try { sock = new Socket(HOST, PORT); in = new BufferedReader( new InputStreamReader( sock.getInputStream() )); out = new PrintWriter( sock.getOutputStream(), true); new TourWatcher(this, in, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page