jeromegn Posted February 17, 2014 Share Posted February 17, 2014 Hey there, Just starting with Phaser. I've followed some of the examples' code and have ran into some troubles regarding timemaps. I get the following error when using `map.fill`: "Uncaught TypeError: Cannot read property 'index' of null" pointing to this: fill: function (index, x, y, width, height, layer) { layer = this.getLayer(layer); this.copy(x, y, width, height, layer); if (this._results.length < 2) { return; } for (var i = 1; i < this._results.length; i++) { this._results[i].index = index; } this.paste(x, y, this._results, layer); },More specifically, line #44265. Here's my own code (in CoffeeScript):preload = -> game.load.image("tiles", "/assets/images/tiles_spritesheet.png") game.load.tilemap('ground', 'assets/platforms.json', null, Phaser.Tilemap.TILED_JSON)create = -> game.stage.disableVisibilityChange = true game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL game.stage.scale.setShowAll() game.stage.scale.refresh() map = game.add.tilemap('ground'); map.addTilesetImage('Premium', 'tiles') layer = map.createLayer('platforms') layer.resizeWorld() map.fill(0, 0, 9, 1, 10)And then my platforms.json:{ "height":10, "layers":[ { "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 57, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 57, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104], "height":10, "name":"platforms", "opacity":1, "type":"tilelayer", "visible":true, "width":10, "x":0, "y":0 }], "orientation":"orthogonal", "properties": { }, "tileheight":70, "tilesets":[ { "firstgid":1, "image":"\/assets\/images\/tiles_spritesheet.png", "imageheight":936, "imagewidth":914, "margin":0, "name":"Premium", "properties": { }, "spacing":2, "tileheight":70, "tilewidth":70 }], "tilewidth":70, "version":1, "width":10}Any idea? I think I have all the "names" right. I used to have errors about that, but fixed them. If I inspect `map._results`, I get:[Object, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, Phaser.Tile, Phaser.Tile, Phaser.Tile, null, null, null, null, null, null, null, null, null, null, null, null, null, null]Seems odd that there would be so many nulls. Using 1.1.5. Link to comment Share on other sites More sharing options...
brejep Posted February 18, 2014 Share Posted February 18, 2014 If the tile is empty, or has the value 0, then Phaser doesn't create a Tile object for it. This causes quite a few problems with Tilemap's methods like fill, copy and paste as they assume a non-null value. I got around this, using the Tiled editor, by filling the whole map with transparent tiles before adding my other tiles. Heppell08 1 Link to comment Share on other sites More sharing options...
jeromegn Posted February 18, 2014 Author Share Posted February 18, 2014 Thanks, that was it! Link to comment Share on other sites More sharing options...
alikoo Posted February 23, 2014 Share Posted February 23, 2014 I had the same problem with "putTile" and here is the way i solved it. Go to the "parseTiledJSON" function in Phaser (1.1.5) and change this condition: if (json.layers.data[t] > 0) to if (json.layers.data[t] >= 0) Link to comment Share on other sites More sharing options...
Recommended Posts