jjwallace Posted July 5, 2016 Share Posted July 5, 2016 Uncaught ReferenceError: map1 is not defined For the life of me cannot find out why map1 is not found var map; var coins; var layer; var sprite; BasicGame.Game3.prototype = { create: function () { console.log('Game Launched'); this.camera.flash('#006600'); this.loadVars() this.loadLevel(); this.renderGame(); //this.input.onDown.add(this.fire, this); }, fire: function () { }, loadVars: function(){ }, loadLevel: function(){ this.load.tilemap('map1', 'assets/lvl/collision_tests.json', null, Phaser.Tilemap.TILED_JSON); this.load.image('ground_1x1', 'assets/tiles/ground_1x1.png'); this.load.image('walls_1x2', 'assets/tiles/walls_1x2.png'); this.load.image('tiles2', 'assets/tiles/tiles2.png'); // this.load.tileset('ground_1x1', '/assets/tiles/ground_1x1.png', 72, 72); // this.load.tileset('walls_1x2', '/assets/tiles/walls_1x2.png', 72, 72); // this.load.tileset('tiles2', '/assets/tiles/tiles2.png', 72, 72); }, renderGame: function() { console.log(map1); map = this.add.tilemap('map1'); <<<<< ERROR IS HERE!!!!!!!!!!!!!!!!!!!! console.log('Map loaded'); Link to comment Share on other sites More sharing options...
LTNGames Posted July 5, 2016 Share Posted July 5, 2016 What does your console output for you when you log 'this', so console.log(this); ? As far as I know you need to add it via game, so something like this below. this.game.add.tilemap('map1'); Unless 'this' is referring to your game object, which in that case it should be working. Link to comment Share on other sites More sharing options...
drhayes Posted July 5, 2016 Share Posted July 5, 2016 For sure that "console.log(map1);" is going to throw an error -- there's nothing named "map1" in that function scope. That's a ReferenceError. Generally, in Phaser, you want this object to be a state object with a "preload" and a "create" method. You then pass that state object to the Phaser.Game constructor. That way, "create" won't be called until the loader is done loading everything you told it to load in "preload". Right now, you are telling Phaser to load a tilemap called "map1" and then immediately asking it to add the tilemap named "map1". It hasn't loaded it yet. Check out this state example to see what I mean: http://phaser.io/examples/v2/p2-physics/state-reset Link to comment Share on other sites More sharing options...
Recommended Posts