I have been working through the tutorials on the Learning jME page and I am trying to get the hang of keyInputs so I tried making my own example, here is my code:
/**
* @author Josh Branchaud
* @version 12/2/2008
*/
// imported classes
import com.jme.app.SimpleGame;
import com.jme.scene.shape.Box;
import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
public class moveableBox1 extends SimpleGame
{
// make a variable for the KeyBindingManager
KeyBindingManager KBM = KeyBindingManager.getKeyBindingManager();
Box box1, box2;
protected void simpleInitGame()
{
// create boxes, box1 to be moved, box2 to be a point of reference
box1 = new Box("moverBox", new Vector3f(0,0,0), new Vector3f(5,5,5));
box2 = new Box("staticBox", new Vector3f(0,0,0), new Vector3f(1,1,1));
// give bounding to both of the boxes
box1.setModelBound(new BoundingBox());
box1.updateModelBound();
box2.setModelBound(new BoundingBox());
box2.updateModelBound();
// attach the boxes to the rootNode
rootNode.attachChild(box1);
rootNode.attachChild(box2);
// add some keybindings
KBM.set("moveUp", KeyInput.KEY_T);
KBM.set("moveDown", KeyInput.KEY_G);
KBM.set("moveLeft", KeyInput.KEY_F);
KBM.set("moveRight", KeyInput.KEY_H);
}
protected void simpleUpdate()
{
if(KBM.isValidCommand("moveUp", false))
{
Vector3f centerVector = box1.getCenter();
box1.setLocalTranslation(centerVector.add(new Vector3f(0,1,0)));
}
if(KBM.isValidCommand("moveDown", false))
{
Vector3f centerVector = box1.getCenter();
box1.setLocalTranslation(centerVector.add(new Vector3f(0,-1,0)));
}
if(KBM.isValidCommand("moveLeft", false))
{
Vector3f centerVector = box1.getCenter();
box1.setLocalTranslation(centerVector.add(new Vector3f(-1,0,0)));
}
if(KBM.isValidCommand("moveRight", false))
{
Vector3f centerVector = box1.getCenter();
box1.setLocalTranslation(centerVector.add(new Vector3f(1,0,0)));
}
}
public static void main(String[] args)
{
moveableBox1 thisWorld = new moveableBox1();
thisWorld.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
thisWorld.start();
}
}
When I run the above code, it appears fine and seems to run fine except I can't seem to move more than 1 unit in any direction... I was hoping to achieve the effect of moving as much as you wanted in any direction depending on the given key input.
T is up, G is Down, F is left, and H is right. I was hoping to ignore the fact that T has two functions if that is possible.
Any ideas on how to make this program do what it is suppose to?