Dynamic objects and code

Hi JME3,

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.

Sounds backwards to me, it’s the AppState that manages stuff, not the other way round.

You probably want to create a Player inside the AppStatePlayer, and initialize the platform inside the AppStatePlatform.

But as @jayfella said, your question is too vague.

Yes, this is Control i need to add to objects.
What are the main differences between AppStates and Control ? Both can run the same code.

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.

AppStates dynamically extend an “application”.

Controls dynamically extend a spatial.


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 ?

Though it’s easy for prototyping, beware of using Spatials as your game objects. It’s a trap that’s hard to get out of later.

1 Like

Is Spatial and Control only for prototyping ?
Why Spatial is so bad ? why it is included in JME3 then ?

Is there some example showing a good way to glue together dynamic objects and code at design time in the editor without coding it ?

No… but treating spatial like a GAME OBJECT is bad except for prototyping.

Spatials are the view of your game objects… but they are not game objects.

JME is not Unity. You have to write code to code things.

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.

You can also configure Controls and add them to the objects using the jME SDK’s Scene Composer. Then save/load it as a j3o file.

Thank you.
I found a video tutorial

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.

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.

You can add custom parameters to Controls with InputCapsule/OutputCapsule.

AbstractControl has an example implementation of the read/write methods.

What do you use if not SDK ?

I’ll try some things and share what i can come with.

I personally use IntelliJ community edition and reference the jme libraries using gradle.

project.ext {
    jmeVer = "[3.2,)"

dependencies {
    implementation "org.jmonkeyengine:jme3-core:$jmeVer"
    implementation "org.jmonkeyengine:jme3-lwjgl:$jmeVer"
    implementation "org.jmonkeyengine:jme3-desktop:$jmeVer"
    implementation "org.jmonkeyengine:jme3-effects:$jmeVer"

Then I just extend SimpleApplication from the Main class and away I go.