I have one AppStatePlayer for Player and an AppStatePlatform for other moving platforms.
Each platform can have it’s own speed using AppStatePlatform speed variable.
What is the best way to assign an AppStatePlayer to Player object and AppStatePlatform to each moving platforms at game initialization ?
You don’t generally use appstates like that. You probably want a Control instead. But you haven’t specified what these appstates do, so it’s diffucult to delve any deeper.
AppStates are for controlling the state of a game. So as a rule you only use one instance of them. For example a main menu state. An input control state. A game over state etc. You can control and map input, a GUI, the whole scene, etc… I.e. a game state.
Controls are for controlling individual scene objects and their behaviours. For example a Rigidbody control moves a model object according to the physics engine. A LOD control would control a scene objects level of detail according to its distance from the camera.
An appstate gives you the whole application so it lets you in essence contain a state of the game, whereas a control only gives you access to the spatial it is attached to and so lets you control its individual state.
I guess you could use an appstate as a replacement for a control if you wanted to. I mean there’s nothing stopping you. But that’s the flow of the API. I guess the key words are encapsulation and disambiguation.
In the sense of “composition is preferred over inheritance”, app states and controls are ways to “extend” the application and spatials (respectively) using composition instead of subclassing.
I see.
Appstate is about game states, controls loading assets.
Control is for Game objects behaviors , the player, characters or some interactive objects.
Is there some project available with Controls ?
Create a class that extends AbstractControl. Use the .getSpatial() method in the control to get the spatial that the control is attached to. Use the update method in your control to update the behaviour of the spatial. Add the control to the spatial using spatial.addControl(myControl) and that spatial will have the behaviour you defined.
This means, during game initialization i must go through all dynamic objects, depending on type object i add one or another Control type.
It would be nice JME3 to propose a way to attribute code to some object without coding.
Objects with custom control are running when viewing in scene composer.
Is there some way to have their custom Controls running only when i launch Main class and not active in scene composer ?
What about giving the possibility to bind custom AppState to objects in Scene composer ?
I disable them in the Scene Composer and use a SceneGraphVisitor in the loading code to enable them.
I’d also like to know if there’s a better way. If for example a RotationControl (like in the video above) stays enabled in the Scene Composer, it will update the Spatial’s rotation. Those altered values are then saved with the j3o file and will be different after each save.
I’d rather keep the defined values as the initial state. Is there a way to only update the view in the Scene Composer?
I guess I could add more parameters to the Control to define the initial values, but… extra work!
Parameters seem to be fixed list in Node Properties.
JME3 needs a code layer to allow adding AppStates to objects in ScenComposer.
Also allow display and modify custom properties in the Node Properties from a custom AppState class.
@properties_variable
float speed = 8f;
Those two things will make things easier without re inventing the wheel again.
Just a reminder that this is open source and does welcome contributions, especially in the SDK. It doesn’t receive a lot of attention of late. I for one, and I do not speak for everybody, don’t even use the SDK. A lot of people would especially appreciate some SDK attention.
As for the engine, I’ve rarely if ever encountered a problem. It is very solid.