When you notice that a control class has ambitions to make decisions on the application level, this is a sign that this control class has evolved to something else—an application state (AppState). We want the application to do the same thing as before—let us chase the random subset of cubes that carry the CubeChaserControl
class.
Create an
AppState
classCubeChaserState
that extends theAbstractAppState
class from thecom.jme3.app.state
package. This class will contain our game logic.Copy the following minimum template into the
CubeChaserState
class:public class CubeChaserState extends AbstractAppState { @Override public void update(float tpf) {} @Override public void cleanup() {} @Override public void initialize(AppStateManager stateManager, Application app) {} }
Move the
makeCubes()
andmyBox()
methods from theCubeChaserControl
class into theCubeChaserState
class; we want to reuse...