GameControl used indirectly for node speed


I realised I was being a bit thick before, and am now converting everything accross to a custom GameControl class.

I have a wierd scenario where the speed for the node is set indirectly.

So the controller is used to set the sail position, then depending on which way the node is facing its speed is calculated and the speed is then applied to the node as a forwardaction.

Does this make sense?

So I want to use say the W key to pull in the sail, and if the sail is full the node speeds up, but if the sail is empty you need to keep pressing W until your sail is full…


That sounds fine…you might take a look at ActionRepeatController (I believe that's what it's called). It should be in or near the GameControls package. It allows you to leverage a GameControl to invoke an action over and over based on time.  For example, in your case, you want to pull up the sails, but obviously you don't want the sails to fly up almost immediately when they hold down 'W'.  The ActionRepeatController will allow you increase sails based on a time frequency you can specify. There's a bunch of nifty little helper controllers in there you might be interested in further looking at. :slight_smile:

I am trying it, but I get this error:

java.lang.ClassCastException: compsci.sailtastic.WiiInputController$3 cannot be cast to java.lang.Runnable

at compsci.sailtastic.WiiInputController.<init>(

at compsci.sailtastic.EngineWithWater.buildInput(

at compsci.sailtastic.EngineWithWater.simpleInitGame(




at compsci.sailtastic.EngineWithWater.main(

27-Apr-2008 11:48:24 cleanup

INFO: Cleaning up resources.

27-Apr-2008 11:48:24 start

INFO: Application ending.

I am not sure how to convert the control:

forward1 is a GameControlAction, this code worked with ActionController, but when I change to ActionRepeatController I get the error above.

    root.addController(new ActionRepeatController(manager.getControl("Forward"), 200, forward1));

Also I cannot get KeyNodeForwardAction to work with the player, is it best to set up say one ThrottleController and edit that for pace?

take a look at TestSwingControlEditor.

you simply implement a runnable to execute your action.

      Runnable runnable = new Runnable() {
         private long lastRun;
         public void run() {
            if (lastRun == 0) lastRun = System.currentTimeMillis();
  "KABOOM: " + (System.currentTimeMillis() - lastRun));
            lastRun = System.currentTimeMillis();
      // Fire action can only occur once per second
      state.getRootNode().addController(new ActionRepeatController(manager.getControl("Fire"), 1000, runnable));

I am also not sure about the keynodeforwardaction thing, when you use GameControllers do you need to use something else to control the speed of a node?

KABOOM! I remember writing that…I'm hilarious.  :smiley:

Yes, the GameControls aren't compatible with the other actions and such.

Ah! That could be a minor problem… am I only allowed to use a throttlecontroller to adjust the velocity of a node?

The problem with it is I need to change the values within the throttlecontroller, and I can't seem to do it?

does anyone know how to do this? I think all is to set a velocity value to a node, and then change it for the different inputs.

Or is it possible to adjust the values of a throttlecontroller whilst it is in use?

ThrottleController was meant more as an example for which other controllers based on a GameControl could be designed.  It's a trivial thing to create your own controllers for use with a GameControl and you can always extend an existing controller.

Thanks! Sorry I dont think I really understand game controls fully, but now looking in the throttlecontroller class it makes sense.