Package edu.ups.gamedev.examples.one

Source Code of edu.ups.gamedev.examples.one.Example

package edu.ups.gamedev.examples.one;

import com.captiveimagination.jgn.synchronization.SyncObjectManager;
import com.captiveimagination.jgn.synchronization.message.SynchronizeCreateMessage;
import com.captiveimagination.jgn.synchronization.message.SynchronizeRemoveMessage;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;

import edu.ups.gamedev.player.PlayerSphere;

public class Example implements SyncObjectManager {
  protected Node scene;
 
  public void setScene(Node scene) {
    this.scene = scene;
  }

  //called when a remote host requests an object be created
  public Object create(SynchronizeCreateMessage scm) {
    System.out.println("Adding player");
    return buildRemotePlayer();
  }

  //called when a remote host requests an object be removed
  public boolean remove(SynchronizeRemoveMessage srm, Object obj) {
    PlayerSphere s = (PlayerSphere)obj;
    System.out.println("Removing player " + s.getName());
    return s.removeFromParent();
  }
 
  //generator function to create new PlayerSpheres for remote players
  private PlayerSphere buildRemotePlayer() {
    PlayerSphere s = new PlayerSphere("remoteSphere", ColorRGBA.green.clone());
    scene.attachChild(s);
    scene.updateGeometricState(0, true);
    s.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
    scene.updateRenderState();
    return s;
  }
}
TOP

Related Classes of edu.ups.gamedev.examples.one.Example

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.