Jump to content

Issue with tilemap.putTile


Prox
 Share

Recommended Posts

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 undefined

I 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

  • 1 year later...
 Share

  • Recently Browsing   0 members

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