I am working on a 3D 2048-game using Java with LWJGL to gain some 3D math and OpenGL experience. I built a small scene-graph (GroupNode and Box). My problem is that the tree structure of my scene-graph is not very convenient for the game-logic. For the game-logic I would use a 2D-array to store the tile-values, merge tiles and calculate points and so on. I think it would be a good approach to separate the view (SceneNodes) from the game-logic-type (Tile). What is best practice to link them, update views, and how to care about animations? If I merge two tiles and present this by move the source tile into the target tile, I need to know when the animation finished to do the next merge-move.
Im not sure, what the "best practice" would be, but maybe what a good approach would be.
If you want to keep your seperation for view and game logic like that, consider adding sort of 'events' ir 'states' that do sort of their thing. Somethinglike "Start Animation" that blocks any input and starts the anmation of given tiles to merge. As the animation takes place, a certain time frame is given, after that the state is set back, whice should corrrespond to the time for the animation.
If you have an overarching game class with the game loop, this could keep the state, so neither your game logic nor your view need to be linked.
So, first your game logic detects a merge and sets the state with additional information of the two merger. Your view checks the state and draws like normal in addition to do the animation. After everything is done, in the last frame of animations, your view sets back the state, so inputs are processed again.
What is important to realise is, that neither your game logic nor your view are the sole owner of the tile information. Both of them need access to the data to draw and process.