1 decade ago by Yojimbo
I created a main menu, but it's a separate game class from the actual game class. For development purposes, I'm just keeping it as a simple level select menu, but right now I have it so when you select a level, it will set a variable that's a scope above both classes, and the new game will load the level based on that variable.
I want to remove that variable and be able to pass an initial level to load to the actual game as it's initializing. Without changing Impact's code, is there a way I can do this that's already built in?
Example:
Could I instantiate the game object, give it a new property of `levelToLoad` and pass it along?
Edit: Hmm... Well, I modified the prototype for the game:
And that's how I'm handling it at the moment. I still feel like it's inappropriate to rely on modifying the prototype, though. I guess it doesn't matter too much, since it's only for development right now.
I want to remove that variable and be able to pass an initial level to load to the actual game as it's initializing. Without changing Impact's code, is there a way I can do this that's already built in?
Example:
ig.module( 'game.main' ) .requires( //Derp stuff derp ) .defines(function () { var levelToLoad = null; // These are two actions that are defined // for the buttons that are both on the main menu // as well as the in-game menu for loading other levels. var actBtnCityScape = function(){ levelToLoad = LevelFirstdraft; if(this.highlighted) { ig.system.setGame(MyGame); } }; var actBtnAnimEx = function() { levelToLoad = LevelAnimationexamples; if(this.highlighted) { ig.system.setGame(MyGame); } }; var MainMenu = ig.Game.extend({ update: function() { // Update all entities and backgroundMaps this.parent(); // Update the GUI Master updateMainMenu.bind(this)(); ig.guimaster.update(); /* My 'GUI Master' is what handles which level is being selected and passes that to the 'levelToLoad' variable above. All the other drawing and init jazz is in there */ } }); var MyGame = ig.Box2DGame.extend({ //... stuff ... init: function () { Box2D.SCALE = 0.05; // Initial Level/Screen Load this.loadLevel(levelToLoad); //... Other stuff ...
Could I instantiate the game object, give it a new property of `levelToLoad` and pass it along?
Edit: Hmm... Well, I modified the prototype for the game:
MyGame.prototype._levelToLoad = LevelFirstdraft;
And that's how I'm handling it at the moment. I still feel like it's inappropriate to rely on modifying the prototype, though. I guess it doesn't matter too much, since it's only for development right now.