Prox Posted October 30, 2014 Share Posted October 30, 2014 Hello ! I'm new with Phaser and I have some issue whem I want to fill a tilemap with 2 types of tile.var TILE_SIZE = 20;var map;var layer;var player;var game = new Phaser.Game(600, 600, Phaser.AUTO, 'Fill Zone', { preload: preload, create: create, update: update });function preload(){ map = game.add.tilemap(); game.load.image("wng", "img/wng.png");}function create(){ map.addTilesetImage('tiles', "wng"); layer = map.create('Tile Layer 1', 10, 10, TILE_SIZE, TILE_SIZE); layer.resizeWorld(); for(var i = 0; i < 20; i++){ for(var j = 0; j < 20; j++){ map.putTile(0,1,j,layer);//Index 0 works each time } } map.putTile(1,3,3,layer);//Index 1 never works Throw : Uncaught TypeError: Cannot read property '2' of undefined }This is the version I actually have. This code not works when it comes to create the second type of tile.You may say try with 2 different tiles and not a spritesheet. I also did this : var TILE_SIZE = 20;var map;var layer;var player;var game = new Phaser.Game(600, 600, Phaser.AUTO, 'Fill Zone', { preload: preload, create: create, update: update });function preload(){ map = game.add.tilemap(); game.load.image("wall", "img/wall.png"); game.load.image("ground", "img/ground.png");} function create(){ map.addTilesetImage('wall'); map.addTilesetImage('ground'); layer = map.create('Tile Layer 1', 10, 10, TILE_SIZE, TILE_SIZE); layer.resizeWorld(); for(var i = 0; i < 20; i++){ for(var j = 0; j < 20; j++){ map.putTile(0,1,j,layer);//Work } } map.putTile(1,3,3,layer);//Don't work Throw : Uncaught TypeError: Cannot read property '2' of undefined }I have exactly the same error ! Uncaught TypeError: Cannot read property '2' of undefinedI thing it's a problem with the tile's index but I don't know how to access it. Create instances for each tile may be a solution two, but I didn't found how to do in the doc. Here is a link if you want to check the code : http://poillic.com/games/phaser Hope you can help me with this hell. Link to comment Share on other sites More sharing options...
Prox Posted October 30, 2014 Author Share Posted October 30, 2014 Error fixed ! When you don't precise an gid with addTilesetImage the last tileset created override those created before. map.addTilesetImage("TheGround", 'ground', TILE_SIZE, TILE_SIZE, 0, 0, 1);map.addTilesetImage("TheWall", 'wall', TILE_SIZE, TILE_SIZE, 0, 0, 0); BastardCode 1 Link to comment Share on other sites More sharing options...
P4nch0 Posted January 13, 2016 Share Posted January 13, 2016 Hi, Do you have any trouble with collide added tiles? I have a poblem, when i add tile to the map when i clik, tile is colliding with player, but when i add it in loop from data base, player isnt colliding with added tile.. Link to comment Share on other sites More sharing options...
Recommended Posts