Jump to content

Tilemap Working example


krazyjakee
 Share

Recommended Posts

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

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

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 tilemap

http://www.kobaltic.com/webGames/COR/public_html/index.html

Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...