1 decade ago by FelipeBudinich
I was looking for a way of passing around data between diferent instances of ig.game instead of storing them in a global variable, and I stumbled upon this plugin.
But since I wasn't comfortable with injecting ig.System and ig.Game at the same time, I decided to look for an alternate way of doing that, so I came up with this:
It passes the data around manipulating the prototype of the ig.Game object before instancing it. it is quite simple to use:
You can get the code from this repo
But since I wasn't comfortable with injecting ig.System and ig.Game at the same time, I decided to look for an alternate way of doing that, so I came up with this:
/*global ig*/
ig.module(
'plugins.scene.manager'
).requires(
'impact.impact'
).defines(function () {
'use strict';
ig.SceneManager = ig.Class.extend({
staticInstantiate: function (ignore) {
this.alias('scene');
return ig.SceneManager.instance || null;
},
alias: function (name) {
Object.defineProperty(ig, name, {
value: this
});
},
init: function () {
ig.SceneManager.instance = this;
},
set: function (scene, data) {
var key;
for (key in data) {
if (data.hasOwnProperty(key)) {
scene.prototype[key] = data[key];
}
}
ig.system.setGame(scene);
}
});
return new ig.SceneManager();
});
It passes the data around manipulating the prototype of the ig.Game object before instancing it. it is quite simple to use:
var data = { message: 'It Works!' };
ig.scene.set(ig.SceneTitle, data);
You can get the code from this repo
