rishavs Posted February 9, 2016 Share Posted February 9, 2016 <!DOCTYPE HTML> <html> <head> <title>Phaser Tiled Test</title> </head> <body> <div id="renderer_container"> <!-- /renderer_container --> </div> <script src="phaser.min.js"></script> <script src="main.js"></script> </body> </html> var map; var layer; var keyArrow; var game = new Phaser.Game(800, 600, Phaser.AUTO, 'renderer_container', { preload : preload, create : create, update : update, render : render }); function preload() { game.load.tilemap('map', 'testMap.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'map.png'); } function create() { map = game.add.tilemap('map'); // Now add in the tileset map.addTilesetImage('tiles'); // Create our layer layer = map.createLayer(0); // Resize the world layer.resizeWorld(); // Allow keyArrow to scroll around the map keyArrow = game.input.keyboard.createCursorKeys(); var help = game.add.text(16, 16, 'Arrows to scroll', { font : '14px Arial', fill : '#ffffff' }); help.fixedToCamera = true; } function update() { if (keyArrow.left.isDown) { game.camera.x -= 4; } else if (keyArrow.right.isDown) { game.camera.x += 4; } if (keyArrow.up.isDown) { game.camera.y -= 4; } else if (keyArrow.down.isDown) { game.camera.y += 4; } } function render() {} Hi Just learning phaser. I am trying to load a simple tiled map. But i am getting an undefined exception for the "map" object. Link to comment Share on other sites More sharing options...
fillmoreb Posted February 9, 2016 Share Posted February 9, 2016 I've copied your code locally, changing it only to use an image and tilemap json I had on hand, and it runs fine. Post a copy of your image and your json, and I'll see if I get the same error as you when I use those. Link to comment Share on other sites More sharing options...
rishavs Posted February 22, 2016 Author Share Posted February 22, 2016 Hi Sorry, I was on vacation for a while. Attaching the map that I used. Hopefully you can tell me what am i doing wrong. Thanks. testMap.json Link to comment Share on other sites More sharing options...
rishavs Posted March 11, 2016 Author Share Posted March 11, 2016 Sorry for thread necromancy. But can anyone help? Link to comment Share on other sites More sharing options...
drhayes Posted March 11, 2016 Share Posted March 11, 2016 Turn off compression in Tiled when you save your map. Everything else looks okay. Link to comment Share on other sites More sharing options...
rishavs Posted March 15, 2016 Author Share Posted March 15, 2016 I am now getting Quote Uncaught TypeError: map.addTilesetImage is not a function from main.js:34 Link to comment Share on other sites More sharing options...
P4nch0 Posted March 15, 2016 Share Posted March 15, 2016 Try to add the name of tile set what you give in tiled editor, like this example: // 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'); http://phaser.io/examples/v2/loader/load-tilemap-json Link to comment Share on other sites More sharing options...
rishavs Posted March 15, 2016 Author Share Posted March 15, 2016 didnt help. I am thinking the problem is in the map = game.add.tilemap('mapJSON'); line. If it had worked properly, i should have that method in my map object. Link to comment Share on other sites More sharing options...
P4nch0 Posted March 15, 2016 Share Posted March 15, 2016 When i try Your code i will be know more, but now i am in work. Maybe try that: this.map.addTilesetImage('tiles'); Link to comment Share on other sites More sharing options...
rishavs Posted March 15, 2016 Author Share Posted March 15, 2016 just did. Didnt work. Thanks for trying.I'll wait till you have run the code. Link to comment Share on other sites More sharing options...
P4nch0 Posted March 15, 2016 Share Posted March 15, 2016 Hi Man, Sory but i cant run your project, i dont know how it work because i dont create it .. I am not sure, but when i try to run isometric map in phaser i cant to do it because that map was unavailable, but maybe someone who knows more can tell You something. Try this course, i was started using phaser with it: https://gamedevacademy.org/html5-phaser-tutorial-top-down-games-with-tiled/ Link to comment Share on other sites More sharing options...
AzraelTycka Posted March 15, 2016 Share Posted March 15, 2016 Hello, I only copied your code and used your files externally and got some errors in console. phaser.min.js:11 Phaser v2.4.6 | Pixi.js v2.2.9 | WebGL | WebAudio http://phaser.io ♥♥♥ phaser.min.js:25 TilemapParser.parseTiledJSON - Only orthogonal map types are supported in this version of Phaser phaser.min.js:20 TypeError: Cannot read property 'length' of undefined(…)f.onload @ phaser.min.js:20 main.js:44 Uncaught TypeError: Cannot read property 'left' of undefined Well unless I missed something from your posts I can even replicate the same error you get. Link to comment Share on other sites More sharing options...
rishavs Posted March 16, 2016 Author Share Posted March 16, 2016 I updated my version of Phaser and I am getting the same error as your are. I am beginning to think this is the culprit - "TilemapParser.parseTiledJSON - Only orthogonal map types are supported in this version of Phaser" My map is staggered isometric. Link to comment Share on other sites More sharing options...
P4nch0 Posted March 16, 2016 Share Posted March 16, 2016 Yeah, this is the same error what i had when i tried to load isometric map. Try normal map, when you have nice tile set, the map can look great too Link to comment Share on other sites More sharing options...
Recommended Posts