Jump to content

Problem with Loading Tilemap created in Tiled


Recommended Posts

Hi All, 


Whilst I have some experience in JavaScript, I am completely new to Phaser and creating games in general so apologies if I have done something really obviously wrong here...


I am trying to follow the example shown here http://phaser.io/examples/v2/loader/load-tilemap-json#gv for loading a Tilemap created in Tiled however I seem to be doing something wrong as although I am trying to follow the instructions in the comments exactly, I am just getting a black box. As shown here http://websitesbymike.co.uk/platformer/


I have checked the console log in Chrome and don't seem to have any errors, have checked the file paths for the images and also the names that I used in Tiled but can't see my error.



Below is the script from my main file and from my json file. If anyone can guide me in the direction of what I am doing wrong it would be hugely appreciated! :)


----------------------------------------------- main.js --------------------------------------------------------------------------------


var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { 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('mymap', 'my_map.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', 'Tiles_32x32.png');
var map;
var layer;
function create() {
    //  The 'mario' key here is the Loader key given in game.load.tilemap
    map = game.add.tilemap('mymap');
    //  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('my_tiles', 'tiles');
    //  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('Tile Layer 1');
    //  This resizes the game world to match the layer dimensions
----------------------------------------------- my_map.json --------------------------------------------------------------------------------
{ "height":20,
         "name":"Tile Layer 1",
Link to comment
Share on other sites

  • 2 weeks later...

First off you might as well add the update to :

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });

If you are going to do anything you will need to call the update. Also I usually add in render too. That is useful for debugging your player information.


The actual problem seems to be that you aren't using CSV as the map type in Tiled. In Tiled, go to Map then map properties. Under Tile layer format select CSV. Save and try again.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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