kenta88 Posted February 16, 2016 Share Posted February 16, 2016 Hi guys, Here turin again I would know if there are any techniques to save the state of game in babylon.js I use a game object as a root of entire canvas (as described into learning babylon.js ebook). I create an angular app and I would to change the route without loose the current game. I thinking about saving the state inside the $rootscope and reload it when I need. But I'm not sure that is a good way. Do you know any idea about it? Thanks Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 16, 2016 Share Posted February 16, 2016 Hello Kenta, The way to save the game state and game context is up to you. As it's different in each game, it cannot be created generically. You'll have to implement it according to your game. Quote Link to comment Share on other sites More sharing options...
amorgan Posted February 17, 2016 Share Posted February 17, 2016 I would suggest isolating your game's state into a separate object, such as Game.savedState, which gets updated either in an interval or on demand. Things you could store in there could be Game.savedState = { playerMeshDetails: { position: scene.playerMesh.position, rotation: scene.playerMesh.rotation }, score: currentScore, someOtherPertinentInfo: data }; Two options that come to mind would be: 1) Build an API that passes the information to a database that can store the object for a given game instance 2) Pass the object through the URI for example: https://jsfiddle.net/v62zdna7/2/ Option 2 is quick and dirty. Either way, it would make sense to reload your game, but if the state needs loaded, the object gets passed and set on load (or whenever you choose to do so) Hope this is helpful, either way it's here for my reference PS: I would not recommend trying to save the ENTIRE Game object that contains the engine, scene, etc. Do so though at your own risk Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted February 17, 2016 Share Posted February 17, 2016 Are you planning on saving the game information on a database, or on the local client? Quote Link to comment Share on other sites More sharing options...
kenta88 Posted March 16, 2016 Author Share Posted March 16, 2016 On 17/2/2016 at 11:50 PM, Pryme8 said: Are you planning on saving the game information on a database, or on the local client? Hi Pryme8, Sorry I see your post post just now. Alligned to amorgan answer, On 17/2/2016 at 5:15 AM, amorgan said: I would suggest isolating your game's state into a separate object, such as Game.savedState, which gets updated either in an interval or on demand. Things you could store in there could be Game.savedState = { playerMeshDetails: { position: scene.playerMesh.position, rotation: scene.playerMesh.rotation }, score: currentScore, someOtherPertinentInfo: data }; I created a method that save some information about position and other stuff inside local storage. This is enough for me. Do you have any different idea about it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.