Izuo Posted March 18, 2014 Share Posted March 18, 2014 This is my first time using Phaser, so I may come off as a total noob lol. I copied the source from the Load Tilemap Json example(Super Mario tilemap). I only changed a few things; the path to the two files and the div that the game loads into. The game loads up, but it only shows the gray background set with game.stage.backgroundColor. I get this error:Uncaught TypeError: Object #<Object> has no method 'addTilesetImage' var game = new Phaser.Game(800, 600, Phaser.AUTO, 'mapPhaser', { preload: preload, create: create });function preload() { // Tilemaps are split into two parts: The actual map data (usually stored in a CSV or JSON file) // and the tileset/s used to render the map. // Here we'll load the tilemap data. The first parameter is a unique key for the map data. // The second is a URL to the JSON file the map data is stored in. This is actually optional, you can pass the JSON object as the 3rd // parameter if you already have it loaded (maybe via a 3rd party source or pre-generated). In which case pass 'null' as the URL and // the JSON object as the 3rd parameter. // The final one tells Phaser the foramt of the map data, in this case it's a JSON file exported from the Tiled map editor. // This could be Phaser.Tilemap.CSV too. game.load.tilemap('mario', 'assets/super_mario.json', null, Phaser.Tilemap.TILED_JSON); // Next we load the tileset. This is just an image, loaded in via the normal way we load images: game.load.image('tiles', 'assets/super_mario.png');}var map;var layer;function create() { game.stage.backgroundColor = '#787878'; // The 'mario' key here is the Loader key given in game.load.tilemap map = game.add.tilemap('mario'); // The first parameter is the tileset name, as specified in the Tiled map editor (and in the tilemap json file) // The second parameter maps this name to the Phaser.Cache key 'tiles' map.addTilesetImage('SuperMarioBros-World1-1', 'tiles'); //The line above is triggering the error. // Creates a layer from the World1 layer in the map data. // A Layer is effectively like a Phaser.Sprite, so is added to the display list. layer = map.createLayer('World1'); // This resizes the game world to match the layer dimensions layer.resizeWorld();}Thanks for reading. Link to comment Share on other sites More sharing options...
rich Posted March 18, 2014 Share Posted March 18, 2014 Something has gone wrong when it creates your tilemap object. Do a console.log(map) and see what you get. Also check in your browser dev tools that the map json file has actually loaded and not 404d or similar. Link to comment Share on other sites More sharing options...
Izuo Posted March 19, 2014 Author Share Posted March 19, 2014 Thanks for the reply, Rich!I figured out what the problem was. I was using an older version of Phaser. The phaser.min.js file used in the tutorial is v1.1.3 and I had used it instead of v2.0.0.Simple mistake on my end. Awesome framework by the way, this is some great stuff! Link to comment Share on other sites More sharing options...
Recommended Posts