Jump to content

Replacing tile in tilemap - can't read index of null


Raicuparta
 Share

Recommended Posts

Want the grass to move when the player steps on it. Have 4 layers on my tilemap, one of them exclusively for the grass.

Have this function:

	    moveGrass: function(x, y) {	    	_map.replace(18, 20, _layer[1].getTileX(x), _layer[1].getTileY(y), 1, 1, 'Grass1');	    }

And I pass the player's x and y as arguments. _layer is an array of layers, and 'Grass1' is the layer with the grass I wanna repalce.

I get this error:

 

 

 

 

  1. Uncaught TypeError: Cannot read property 'index' of null phaser.min.js:15
    1. b.Tilemap.replacephaser.min.js:15
    2. moveGrassLevel.js:53
    3. b.StateManager.updatephaser.min.js:6
    4. b.Game.updatephaser.min.js:8
    5. b.RequestAnimationFrame.updateRAFphaser.min.js:11
    6. window.requestAnimationFrame.forceSetTimeOut._onLoopphaser.min.js:11

 

Even tried it with different layers, still get this error, not sure what index the error is referring to.

 

EDIT: So it seems the problem is that the blank tiles are null so I can't attempt to replace them. So I just need to be more careful with choosing a tile to replace, or fill the entire screen with invisible tiles.

Edited by Raicuparta
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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