Jump to content

How to save the state of game


kenta88
 Share

Recommended Posts

Hi guys,

Here turin again :D

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 ;)

Link to comment
Share on other sites

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 :D

 

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

Link to comment
Share on other sites

  • 4 weeks later...
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? 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...