Ok, here’s how this is setup, hack of jme3,
I have a state that’s does nothing but initialize nodes for the game,
//setup minimap
miniMapNode = new Node("miniMapNode");
miniMapGuiNode = new Node("miniMapGuiNode");
miniMapWaterNode = new Node("miniMapWaterNode");
miniMapNode.attachChild(miniMapWaterNode);
miniMapGuiNode.setQueueBucket(RenderQueue.Bucket.Gui);
miniMapGuiNode.setCullHint(Spatial.CullHint.Never);
The update method for the state,
@Override
public void update(float tpf) {
miniMapNode.updateLogicalState(tpf);
miniMapGuiNode.updateLogicalState(tpf);
}
The render method,
@Override
public void render( RenderManager rm ) {
miniMapNode.updateGeometricState();
miniMapGuiNode.updateGeometricState();
}
The state that creates characters adds a minimap,
/**
* Add a MiniMapCamera to a node.
* @param player The node to add the camera to. Also the node the camera
* will lookAt.
* @param camera The cammera to clone for setting the MiniMap ViewPort scene.
* @param chaseCam If non-null, new buttons with a mouseListener are added
* to the miniMapGuiNode.
*/
public void addMiniMap(Node player, Camera camera, ChaseCamera chaseCam ) {
Camera cam = camera.clone();
cam.setViewPort(.725f, .975f, 0.7f, 0.95f);
ViewPort miniMapViewPort = getApplication().getRenderManager().createMainView("MiniMapView", cam);
miniMapViewPort.setClearFlags(true, true, true);
//Attach scenes
miniMapViewPort.attachScene(getState(InitSceneGraphTreeState.class).getMiniMapNode());
miniMapViewPort.attachScene(getState(InitSceneGraphTreeState.class).getTerrainNode());
miniMapViewPort.setBackgroundColor(ColorRGBA.Black);
//Create the FilterPostProcessor for the ViewPort
FilterPostProcessor miniMapProcessor = new FilterPostProcessor(getApplication().getAssetManager());
miniMapViewPort.addProcessor(miniMapProcessor);
//Add filters
createFilters(miniMapProcessor);
createShallowWaterB(miniMapViewPort);
createShallowWaterC(miniMapViewPort);
//Add MiniMapCamera to player node.
MiniMapCamera miniMapCam = new MiniMapCamera(cam, player, getApplication().getInputManager());
//Never hide cursor if used for picking.
miniMapCam.setHideCursorOnRotate(false);
//Set the camera to look down from above
miniMapCam.setDefaultVerticalRotation(1.57f);
//Set camera to face player on start.
miniMapCam.setDefaultHorizontalRotation(1.57f);
miniMapCam.setRotationSpeed(4f);
miniMapCam.setDefaultDistance(40);
// Create a new cam for the guiNode
Camera miniMapGuiCam = cam.clone();
ViewPort miniMapGuiViewPort = getApplication().getRenderManager().createPostView("MiniMapGuiViewPort", miniMapGuiCam);
//Attach scenes
miniMapGuiViewPort.attachScene(getState(InitSceneGraphTreeState.class).getMiniMapGuiNode());
miniMapGuiViewPort.setClearFlags(false, false, false);
//Add picking to the guiNode
getState(PickState.class).addCollisionRoot(getState(InitSceneGraphTreeState.class).getMiniMapGuiNode(), miniMapGuiViewPort, PickState.PICK_LAYER_GUI);
//If a ChaseCamera is supplied, add buttons to the GUI node and add a
//MouseListener for the click() method.
if (chaseCam != null) {
Node compassNode = addButton("Compass", "Interface/compass64.png", 128, 128, 0.15f, 0.85f, true);
getState(InitSceneGraphTreeState.class).getMiniMapGuiNode().attachChild(compassNode);
//Set the node to rotate when the MiniMapCamera rotates.
miniMapCam.setCompassButton(compassNode);
//Add the MouseListener that will control what happens when user
//clicks the compass button. Controls both the ChaseCamera and
//MiniMapCamera rotation by CameraInput.CHASECAM_TOGGLEROTATE,
//CameraInput.CHASECAM_MOVELEFT, or CameraInput.CHASECAM_MOVERIGHT
//mappings. The MouseListener click() method will reset both the
//ChaseCamera and MiniMapCamera to face north on the
//MouseInput.BUTTON_LEFT click or south on
//MouseInput.BUTTON_RIGHT click.
MouseEventControl.addListenersToSpatial(compassNode, new DefaultMouseListener() {
@Override
protected void click( MouseButtonEvent event, Spatial target, Spatial capture ) {
System.out.println("I've been clicked:" + target + " " + event);
if (event.getButtonIndex() == MouseInput.BUTTON_LEFT) {
//Point the miniMap and chaseCam in the North direction
miniMapCam.setDefaultHorizontalRotation(1.57f);
chaseCam.setDefaultHorizontalRotation(1.57f);
}
if (event.getButtonIndex() == MouseInput.BUTTON_RIGHT) {
//Point the miniMap and chaseCam in the South direction
miniMapCam.setDefaultHorizontalRotation(4.71f);
chaseCam.setDefaultHorizontalRotation(4.71f);
}
}
});
//Add a button that the user can toggle run or walk off and on.
Node runNode = addButton("Run", "Interface/run64.png", 128, 128, 0.15f, 0.15f, true);
getState(InitSceneGraphTreeState.class).getMiniMapGuiNode().attachChild(runNode);
MouseEventControl.addListenersToSpatial(runNode, new DefaultMouseListener() {
@Override
protected void click( MouseButtonEvent event, Spatial target, Spatial capture ) {
System.out.println("I've been clicked:" + target + " " + event);
UserDataControl udControl = player.getControl(UserDataControl.class);
StraightPathAgentControl spaControl = player.getControl(StraightPathAgentControl.class);
int walk = EnumPosType.POS_WALKING.pos();
int run = EnumPosType.POS_RUNNING.pos();
boolean isAutoRun = !udControl.getAutorun();
udControl.setAutorun(isAutoRun);
if (isAutoRun && udControl.getPositionType() == walk) {
udControl.setPositionType(run);
spaControl.setTarget(spaControl.getTarget());
}
else if (!isAutoRun && udControl.getPositionType() == run) {
udControl.setPositionType(walk);
spaControl.setTarget(spaControl.getTarget());
}
}
});
}
}
The relevant lines for finishing setting up the self managed nodes,
//Attach scenes
miniMapViewPort.attachScene(getState(InitSceneGraphTreeState.class).getMiniMapNode()); //self managed
miniMapViewPort.attachScene(getState(InitSceneGraphTreeState.class).getTerrainNode());
// Create a new cam for the guiNode
Camera miniMapGuiCam = cam.clone();
ViewPort miniMapGuiViewPort = getApplication().getRenderManager().createPostView("MiniMapGuiViewPort", miniMapGuiCam);
//Attach scenes
miniMapGuiViewPort.attachScene(getState(InitSceneGraphTreeState.class).getMiniMapGuiNode()); //self managed
miniMapGuiViewPort.setClearFlags(false, false, false);
//Add picking to the guiNode
getState(PickState.class).addCollisionRoot(getState(InitSceneGraphTreeState.class).getMiniMapGuiNode(), miniMapGuiViewPort, PickState.PICK_LAYER_GUI);
I have tried just using MouseAppState by itself.
I have tried just using GUIState by itself which inits GuiGlobals.
I have tried with both initialized.
I have tried all of the above with the methods for creating the miniMapCam inside GuiState and other states.
I have used all getState(PickState.class).addCollisionRoot(yourViewport);
methods using PickState.class and MouseAppState.class.
-
The Listener on the runNode will fire when spamming the mouse inside the main viewport but nothing fires from the miniMapViewPort. It shouldn’t even fire at all from the main viewport.
-
Picking works fine in the miniMapViewPort.
-
The listeners work fine from normal guiNode or when creating a new Camera for the miniMapGuiNode.
I must of missed something somewhere.