Jump to content

Query RE Globals and generator-phaser-official


rolandino
 Share

Recommended Posts

Hi,

Have a question re: codevinsky's rather wonderful "generator-phaser-official" (see http://codevinsky.ghost.io/phaser-tutorial-getting-started-with-generator-phaser-official/).

If I generate a sample project (by running yo phaser-official) it generates a set of JS files in states, five .js files.

What I'd like to know - is - in this structure where can I put global variables. For example, supposing I wanted to hold onto the level a game player is on and didn't wish to use local storage? I can't (and no doubt shouldn't) put it in main.js - that gets overwritten.

So just wondered if anyone had any suggestions?

Many thanks,
R
 

 

Link to comment
Share on other sites

make a small storage yourself.

 

for instance make a file storage.js:

var storage = {}module.exports = storage;

And then just require it:

var storage = require('storage');

after that you can use it in that specific state/prefab/whatever to retrieve / store data:

storage['omgpuppies'] = 'CUTE!';console.log(storage['omgpuppies']);

Data stored is can be retrieved in other states etc due to the require call returning the same dict.

 

This is the simplest example I could come up with. 

Link to comment
Share on other sites

  • 6 months later...

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...