Hello, new to forum so apologies if this is in the wrong spot to ask this… I’m trying to get into some simple game programming, and I’m getting really stuck on storing the data for where objects are located in the game. My first instinct was to store location values in, for example, the Player class. After starting to read through the jME tutorials it seems like locations should all be stored (and changed) directly in the spatials. So I guess an example question would be: If I press the left arrow key to make my character move left, should that change the location of the spatial, or change some value that’s actually stored in my Player class, and then have update read the value and move the spatial? Anyone able to shed some light or point me towards some resources that can explain some design strategies? Thanks.
The tutorials do things as simply as possible but that doesn’t mean it’s a good idea for a real game.
Separating game objects from visualization objects is a good idea. There are numerous strategies for doing that.
Yeah, that’s one thing I really dislike about OOP examples is they use such simple objects… Do you have a suggestion for what strategy to use for my example of character location?
The basic design tactics of JME3 are custom controls (for updatable functions connected with a particular spatial in the scene graph) and appStates (for updatable functions not connected with a particular spatial). These are described in https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_controls and https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:application_states.
Regarding your example, a typical approach might be for your Player class to maintain reference to the spatial which represents the character’s center. The keystroke event would go to Player in order to modify the position of its spatial. In that case it makes sense for the Player class to be a custom control, i.e. a subclass of AbstractControl.
@SvenskNavi said: Yeah, that's one thing I really dislike about OOP examples is they use such simple objects.. Do you have a suggestion for what strategy to use for my example of character location?
Simplest strategy is to have a player object and then some Control that updates the spatial based on the player object.
There are really a few different ways to do things that go in a variety of different directions depending on the end result. For example, for an RTS or an RPG, an Entity System is really popular these days but has its own sizable learning curve associated with it.
Okay, great, thanks guys. =D