Remember our friend, the blue cube from the template? Let's write some code that changes the cube state: the cube has a color, a scale, a location, and a rotation. So just for fun, let's make the cube rotate when we left-click on it, and change its color every time we press the Space bar.
Make another copy of the
BasicGame
project'sMain.java
template and name the classUserInput.java
. Remember to also refactor the first line of themain()
method to the following:UserInput app = new UserInput();.
Define class constants that represent the Space bar and left-click of the mouse. Import the necessary classes from the
com.jme3.input.*
andcom.jme3.input.controls.*
packages.private final static Trigger TRIGGER_COLOR = new KeyTrigger(KeyInput.KEY_SPACE); private final static Trigger TRIGGER_ROTATE = new MouseButtonTrigger(MouseInput.BUTTON_LEFT);
Define two String class constants. We use these Strings to identify the two actions later: rotating the...