krazyjakee Posted February 26, 2014 Share Posted February 26, 2014 I've been browsing and googling for a number of hours but I simply cannot get a tilemap to appear on my screen in 1.1.6. I see different peoples examples using variations and I have tried them all but to no avail. Here is my code:var create, cursors, game, layer, map, player, preload, tileset, update;game = map = tileset = layer = player = cursors = false;preload = function() { game.load.tilemap('map', 'resources/map/island2.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'resources/img/free_tileset_version_10.png', 32, 32); return game.load.spritesheet('character', 'resources/img/6Actor_5.png', 32, 32);};create = function() { game.stage.backgroundColor = '#000000'; map = game.add.tilemap('map'); map.addTilesetImage('tiles'); layer = map.createLayer('layer1'); player = game.add.sprite(2 * 32, 6 * 32, 'character'); game.camera.follow(player); return cursors = game.input.keyboard.createCursorKeys();};update = function() {};game = new Phaser.Game(240, 128, Phaser.AUTO, 'phaser-game', { preload: preload, create: create, update: update});It simply shows a black screen with "Tilemap.createLayer: Invalid layer ID given: null" in the console. Link to comment Share on other sites More sharing options...
jflowers45 Posted February 26, 2014 Share Posted February 26, 2014 Hi, I'm not sure what the problem is with your code without seeing it posted up on a web server. Make sure you have a div called phaser-game? at http://examples.phaser.io you can see a bunch of tilemap examples. I took one and put it up on my own server and made sure it works with phaser 1.1.6 and it works fine - here's the example, hope it helps http://www.flashysubstance.com/tileExample/ Link to comment Share on other sites More sharing options...
Kobaltic Posted February 27, 2014 Share Posted February 27, 2014 Make sure that you have the same name as your layer in tiled. So if you are using layer1 in your code, then your layer name in tiled is also layer1. You could also open your json file and change the name in there. Link to comment Share on other sites More sharing options...
krazyjakee Posted February 28, 2014 Author Share Posted February 28, 2014 I got a little bit further thanks.It looks like although my little dude is there, the tilemap is not. http://www.inputgames.co.uk/jquest/ - any help much appreciated. Link to comment Share on other sites More sharing options...
cheshirepuss42 Posted February 28, 2014 Share Posted February 28, 2014 Try doing this: replace (in init.js,create)map.addTilesetImage('tiles');withmap.addTilesetImage('free_tileset_version_10','tiles');adding the name of the tileset as set in the json fileThat once solved my problem with something like this. (this was actually today) Link to comment Share on other sites More sharing options...
Kobaltic Posted March 1, 2014 Share Posted March 1, 2014 Here is your actual code. You are resizing the layer but you never made a layer to resize. Had you debugged you would have caught the error.create = function() { game.stage.backgroundColor = '#000000'; map = game.add.tilemap('map'); map.addTilesetImage('tiles'); map.setCollisionBetween(1, 12); layer.resizeWorld(); player = game.add.sprite(2 * 32, 6 * 32, 'character'); game.camera.follow(player); return cursors = game.input.keyboard.createCursorKeys();};You should have this in there too (as you do in your code posted on here) layer = map.createLayer('layer1');Here is my test bed with working tilemaphttp://www.kobaltic.com/webGames/COR/public_html/index.html Link to comment Share on other sites More sharing options...
krazyjakee Posted March 2, 2014 Author Share Posted March 2, 2014 Thank you very much guys. Lots to learn. Link to comment Share on other sites More sharing options...
nExt Posted May 7, 2014 Share Posted May 7, 2014 how do create title map format JSON..from image ??? Link to comment Share on other sites More sharing options...
longuyvinh Posted October 30, 2014 Share Posted October 30, 2014 how do create title map format JSON..from image ??? You can use Tiled Map editor , link dowload: http://www.mapeditor.org/ Nicole 1 Link to comment Share on other sites More sharing options...
Recommended Posts