Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by dmen

I am using the ig.system.setGame() method to swap game classes - I am using this to permit different levels, an intro screen, etc.
But I'm not sure where I can stick a global, like a score, in order to access it from the different game classes.
Thanks!

1 decade ago by dmen

OK, noted a method in "Introducing HTML5 Game Development' where he sets a variable on ig, because JS is dynamic. Seems a good enough solution, but I'm doing something wrong.

In my initial game class - introScreen I have this in the init method:

ig.playerData = { score: 0 };

And then try to retrieve it in my second game class - levelOne:

ig.playerData.score += points;

But playerData is undefined...

1 decade ago by TigerJ

I ususally use
ig.game.loadLevelDeffered(LevelMylevel);

to change levels inside my game. This leaves all the ig.game.<variable> objects in place.

For instance in my latest game Saving Circles, in the main.js I have these properties extending
lastScore:0,
bestScore:0,

If the player dies I reload the menu with
ig.game.loadLevelDeferred(LevelMenulevel);

The menu level is a standard level from the weltmeister, which has an entity (menucontroller.js) that handles all the menu items for impactjs and cocoonjs

If they click the play button it loads the play level using loadLevelDeferred
ig.game.loadLevelDeferred(LevelPlaylevel);

TL;DR;
I use weltmeister levels instead of setGame, and load them allowing my extended properties from main.js to persist as global non-resetting values.

edit: Shameless plugs
saving circles web: http://devbriggs.com/savingcircles/
saving circles android: https://play.google.com/store/apps/details?id=com.jimmybriggs.savingcirclesfree

1 decade ago by dmen

Thanks, but that doesn't help - I'm not using weltmeister at all. So, anyone know why setting a variable on ig doesn't work as mentioned in that book?

1 decade ago by dmen

Setting it on window works fine... I'll go with that for now.

1 decade ago by alexandre

Suggestion: use the impact storage plugin by jsantell. Works like a charm.
Page 1 of 1
« first « previous next › last »