/** * This method takes the parent node of a screen that has already been built from the * instantiation of its object. This method then associates the node with the <code>screenID * </code> <code>Key</code> and uses <code>addScreen</code> to load it in the <code>screenMap * </code> * * @param screenID associated string key * @param node screen node value */ public void loadJavaWrittenScreen(String screenID, Node node) { // get top level node Parent parent = (Parent) node; if (parent != null) { // allow use of setScreenParent and setMainApp Controllable javaScreenClass = (Controllable) node; javaScreenClass.setScreenParent(this); javaScreenClass.setMainApp(mainApp); addScreen(screenID, parent); } // TODO remove tests else { System.out.println("java parent is null"); } }
/** * Uses {@link javafx.fxml.FXMLLoader#load() FXMLLoader.load()} to build the screen nodes * expressed by an FXML file to then add it to the <code>screenMap</code> * * @param screenID the ID to be associated with the loaded fxml file's nodes * @param resource relative path to the fxml file to be loaded * @return */ public boolean loadFXMLScreen(String screenID, String resource) { try { FXMLLoader myLoader = new FXMLLoader(getClass().getResource(resource)); // get node Parent parent = (Parent) myLoader.load(); // get the controller and use interface casting to be able to invoke the // .setScreen and .setMainApp methods so that it can be Controllable Controllable fxmlController = (Controllable) myLoader.getController(); // tell the controller that this is the parent node fxmlController.setScreenParent(this); fxmlController.setMainApp(mainApp); // add the node screenMap addScreen(screenID, parent); return true; } catch (Exception e) { return false; } }
public static void updateControl() { if (control == null) { return; } if (Keyboard.isKeyDown(forwardKey)) { control.forward(); } if (Keyboard.isKeyDown(backwardKey)) { control.backward(); } if (Keyboard.isKeyDown(leftKey)) { control.left(); } if (Keyboard.isKeyDown(rightKey)) { control.right(); } if (Keyboard.isKeyDown(upKey)) { control.up(); } if (Keyboard.isKeyDown(downKey)) { control.down(); } }