Best Practices Control

I think I have basically the concept of JME vs. AppState vs. Controls.

My question is about pausing!!!

I have a main AppState, that can go through all the different appStates and enable/disable them when need be.

What about “Controls”, so I have a Node that has Geometry assigned to is and a control that will animation a mesh inside that. When the game goes to pause, what is the best practice to get all the controls to pause?

Is it just inside the update method, check the game paused (field) that you define or is there is simple way to pause all the controls from updating that needs to be.

Just wondering, if the concept is check inside the update method against the games pause or other methods.

THanks for your thoughts.

Define your controls in an array of AbstractControls, then inside your onPause() listener traverse & setEnabled(false) on them, or traverse on the children of your scene node & do child.getControl(AbstractControl.class).setEnabled(false); , but if the object has 2 or more controls then use child.getControl(index) instead.

I think your custom approach is clean too, but that if you want to do it from a jme perspective, as you may reinvent the idea, but doing setPaused instead of setEnabled.

1 Like

Let’s say you have a GameRunningState app state which has a rootNode under which you attach all spatials in your game. On every cycle, for each attached and enabled AppState, the engine calls their update() method. That will include your GameRunningState. The GameRunningState, in turn, should have a call to rootNode.updateLogicalState() in its update() method in order to, you know, update the logical state of your spatials – in other words, it will call the update() method on every Control of every spatial under rootNode.

That said, pausing the game simply consists in disabling the GameRunningState (setEnabled(false)). When you do that the GameRunningState.update() method will not be called by the engine, consequently not updating any Controls in rootNode and its attached spatials.

1 Like