Making a game with cocos2d-js, is there a reliable way to create saved data in my local computer? I see that there is cc.sys.localStorage
but it is removed if the user clears the browser's cache or when they simply use another browser.
|
|||
|
With JavaScript you don't have a way to persist things transparently other than local storage. I don't know anything about cocos2d but this is really a question about JS. If you really need something persisted you have a couple options. First you can fake your browser into thinking you want to download something, you can do this by using a library like https://github.com/eligrey/FileSaver.js. You won't have any control over where the saved file lives on the machine though and likely won't be able to read it back in unless you have the user navigate to it themselves. The second option is just to accept localStorage's limitations. Depending on what you are trying to achieve this is probably a good way to go, just know that not all browsers support it and the amount of data you can store is limited. The third option is to use a server to handle saving the file. I know you asked for how to store something locally, but I think this is your best bet unless you can't require an internet connection. You can write your own or use something like Firebase which is awesome and has a free tier that is pretty solid. |
|||
|