1 decade ago by coreysnyder
I created an entity and added it to weltmeister. In the init method I added a console stmt. When my game starts, I see the init log 3 times in a row. Why would this be? In weltmeister I see it only a single time.
This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact
init: function(x, y, settings){ this.parent(x, y, settings); this.startPos = {x: x, y: y}; this.addAnim('idle', 1, [0]); console.log("INIT"); },
ig.module( 'game.main' ) .requires( 'impact.game', 'impact.font', 'game.levels.level1', 'game.entities.snowball', 'plugins.box2d.game', 'impact.debug.debug', 'game.entities.enemy', 'game.entities.zombie', 'game.entities.zombieelf', 'game.entities.slingshot', 'game.entities.analogstick', 'game.entities.enemyspawner' ) .defines(function(){ MyGame = ig.Box2DGame.extend({ gravity: 200, // All entities are affected by this // Load a font font: new ig.Font( 'media/04b03.font.png' ), clearColor: '#1b2026', currentLevel: null, //Holds the name of the current level init: function() { // Initialize your game here; bind keys etc. ig.input.bind( ig.KEY.LEFT_ARROW, 'screenLeft' ); ig.input.bind( ig.KEY.RIGHT_ARROW, 'screenRight' ); ig.input.bind( ig.KEY.DOWN_ARROW, 'screenDown' ); ig.input.bind( ig.KEY.UP_ARROW, 'screenUp' ); ig.input.bind( ig.KEY.MOUSE1, 'leftclick' ); ig.input.bind( ig.KEY.MOUSE2, "rightclick"); if( ig.ua.mobile ) { //alert("MOBILE"); ig.input.bindTouchArea( 0, 0, 600, 300, 'leftclick' ); } this.loadLevel( LevelLevel1 ); }, update: function() { // Update all entities and backgroundMaps this.parent(); // Add your own, additional update code here if( ig.input.state('screenLeft') ) { this.screen.x = this.screen.x - 5; } if( ig.input.state('screenRight')){ this.screen.x = this.screen.x + 5; } if( ig.input.state('screenUp')){ this.screen.y = this.screen.y - 5; } if( ig.input.state('screenDown')){ this.screen.y = this.screen.y + 5; } if(ig.input.state("leftclick")){ } if(ig.input.state("rightclick")){ } }, draw: function() { // Draw all entities and backgroundMaps this.parent(); // Add your own drawing code here var x = ig.system.width/2, y = ig.system.height/2; this.font.draw( 'It Works!', x, y, ig.Font.ALIGN.CENTER ); }, changeLevel: function(levelName) { // Store the name of the level. this.currentLevel = levelName; // Change map. ig.game.loadLevelDeferred( ig.global[levelName] ); var enemySpawnOrder = Levels[levelName]; } }); /* NOT REALLY USED EXCEPT PLACEHOLDER */ StartScreen = ig.Game.extend({ init: function(){ }, update: function(){ this.parent(); }, draw: function(){ this.parent(); } }); // Start the Game with 60fps, a resolution of 320x240, scaled // up by a factor of 2 ig.main( '#canvas', MyGame, 60, 600, 300, 2 ); });
ig.system.setGame(MyGame); ig.game.changeLevel( levelID );
// in main.js init: function() { // Initialize your game here; bind keys etc. ig.input.bind( ig.KEY.LEFT_ARROW, 'screenLeft' ); ig.input.bind( ig.KEY.RIGHT_ARROW, 'screenRight' ); ig.input.bind( ig.KEY.DOWN_ARROW, 'screenDown' ); ig.input.bind( ig.KEY.UP_ARROW, 'screenUp' ); ig.input.bind( ig.KEY.MOUSE1, 'leftclick' ); ig.input.bind( ig.KEY.MOUSE2, "rightclick"); if( ig.ua.mobile ) { //alert("MOBILE"); ig.input.bindTouchArea( 0, 0, 600, 300, 'leftclick' ); } // UPDATED this.changeLevel('LevelLevel1'); },
ig.main( '#canvas', StartScreen, 60, 600, 300, 2 );
// Store the name of the level. this.currentLevel = levelName;
Has this ever caused you problems in the past? What's the best way to interact with the game outside of the framework? I've been trying to access the game through global vars.
this.currentLevel = levelName;
ig.game.loadLevelDeferred( ig.global[levelName] );
this.loadLevel( LevelLevel1 );
ig.module( 'game.entities.void' ) .requires( 'impact.entity' ) .defines(function(){ EntityVoid = ig.Entity.extend({ _wmDrawBox: true, _wmBoxColor: 'rgba(255, 255, 255, 0.4)', size: {x:24, y:24}, gravityFactor: 0, }); });
getLevelName: function() { var info = this.getEntityByName('info'); return info ? info.level : null; },