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 riceje7

ImpactJS-Plugins by Joe Rice
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * *

PersistantData Plugin
* * * * * * * * * * * * * * * * * * * * * * *

A plugin to maintain data between separate instances of ig.Game for ImpactJS.

Get it HERE

By injecting into ig.System and ig.Game this plugin will allow you to pass a data object
between instances of ig.Game.


Simply require game.plugins.PersistantData in your module, then load your ig.Game class
like normal, but instead pass an optional object as a an additional parameter to the
ig.system.setGame() function.

Example:

ig.module('game.example').require('game.plugins.PersistantData').defines(function(){  
    Game1 = ig.Game.extend({  
        // Put your game code here as you normally would  
        someData: {  
    	    x: 100,  
    	    y: 150  
        },  
        init: function(){  
            ig.system.setGame(Game2, {      //        Notice the extra parameter, which is an object. Though it
                passedData: this.someData   // <====  can be of any data type. However to pass more than one piece of
            });                             //        data an object is needed.
    	}  
    }); 
    Game2 = ig.Game.extend({  
    	    // Put your game code here as you normally would  
    	    passedData: null,  
    	    init: function(){  
    	    // Now you can access the object passed through ig.system.setGame through this.persistantData  
    	    this.passedData = this.persistantData.passedData;  
        }  
    });  
}); 

And its as simple as that. If anyone encounters any bugs, errors, or problems with the plugin
you can shoot me an email [mailto:joerice@foursquaregames.com HERE].

Let me know what you think!

1 decade ago by mimik

Hey nicely done!
No more lazy global vars ;-)

1 decade ago by Joncom

Perhaps I&039;m a little bit noob, but I don't understand what this is or what it would be used for. Would you mind explaining in layman terms when a person would use a plugin like this? Why would someone want to maintain data between separate instances of #ig.Game?

1 decade ago by riceje7

yeah no problem. basically i created it because i needed a way to maintain a set of variables between two or more instances of `ig.Game`. In my specific situation I have a simple html login screen which starts an instance of `ig.Game` where I load up the players data that is either in `LocalStorage` or backed up in a database. from there they can go to a level select screen which is another instance of `ig.Game` and once they select a level it loads yet another instance of `ig.Game` that is the actual game and level they selected. All the while their data is being passed along from one instance to another so it can be loaded into their player `entity`. I am using this method to maintain scores, coins collected, powerups collected, levels completed and a couple of other pieces of information between separate play sessions. so once the player completes a level their progress is saved incase they choose to stop after that particular level. When they come back to play again the data is loaded once more and they can continue where they left off. it may seem confusing but its the best solution I could come up with as i wanted to limit the amount of time the player spends outside of the actual program for things like selecting and starting a level, or choosing settings. (i.e. i built most of my menus inside impact instead of hand coding all the html, css, javascript and such for consistency sake.) hope that answers your questions. let me know if you need any clarification.

1 decade ago by riceje7

Quote from mimik
Hey nicely done!
No more lazy global vars ;-)


true that they really bug me, guess the OOP side of me was irking me to be a little cleaner with my code. lol

1 decade ago by anchpop

It seems to crash when I include impact.debug.debug

10 years ago by FelipeBudinich

I arrived to a different solution to this problem without injecting ig.System or ig.Game, manipulating the prototype of the ig.Game class before instancing it:

https://github.com/Talesay/impact-plugin-scene-manager
Page 1 of 1
« first « previous next › last »