Jump to content

Tile properties in Phaser 1.1.5


Recommended Posts

I'm having a bit of an issue figuring out tile properties in 1.1.5. My understanding is that each tile in a map has an individual set of properties, which can be set in the tile map editor such as Tiled. Here's what I'm doing, screenshots are of Tiled and my game objects being output to the Chrome developer console.


I set the properties for each tile in the tileset in Tiled



In my game, I can then see the tile properties at the Phaser.TileSet.tileProperties object, which I did not find on the documentation.





But the tile properties are not available for each Phaser.Tile object





Are the tile properties from the tile set not supposed to transfer to each individual tile object? I would like to be able to change the values for the properties on each tile as the game is played, so if not I suppose I'll need to set this up myself.





Link to comment
Share on other sites

I've done some work to make a generic example of this. The basic question still is, should each Tile object have the properties set in the editor (Tiled in this case) on the tilesheet? Am I attempting to access the Tile properties correctly?


Example: http://scottedwardcummings.com/phaser-examples/tile-properties/


Open the dev console and note that I've logged a TileMap.TileSet.tileProperties array. You can open this up and see that the tile map has properties set on several tile types such as the mushroom, coin, floor and empty sky.


If you click on any of these, the console will log the tile object of the tile clicked. If you inspect the "properties" object of the tile, nothing will be there. I would expect the tileset properties to get transfered to these tiles so they can be manipulated, but perhaps I am mistaken. Is there another way to set properties on individual tiles in Tiled that is the preferred method? Here is the source:

<html>	<head>	<script src="js/phaser/phaser.js"></script>	<script type="text/javascript">		       		var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });		function preload() {			game.load.tilemap('mario', 'assets/tilemaps/maps/super_mario.json', null, Phaser.Tilemap.TILED_JSON);			game.load.image('tiles', 'assets/tilemaps/tiles/super_mario.png');			}			var map;			var layer;			var p;			var cursors;			var marker;			function create() {				game.stage.backgroundColor = '#787878';				map = game.add.tilemap('mario');				map.addTilesetImage('SuperMarioBros-World1-1', 'tiles');    				layer = map.createLayer('World1');				layer.resizeWorld();				marker = this.game.add.graphics();				marker.lineStyle(2, 0x000000, 1);				marker.drawRect(0, 0, 16, 16);								console.log("TileMap.Tilesets[0].tileProperties")				console.log(map.tilesets[0].tileProperties);			}			function update() {							marker.x = layer.getTileX(game.input.activePointer.worldX) * 16;				marker.y = layer.getTileY(game.input.activePointer.worldY) * 16;					if (game.input.mousePointer.isDown){						var currentTile = map.getTile(layer.getTileX(marker.x), layer.getTileY(marker.y), 'World1');						console.log("Phaser.Tile Object");						console.log(currentTile);						console.log("Phaser.Tile.properties - attemting to access property \'type\'");						console.log(currentTile.properties.type);																}			}	</script>	</head>	<body>			 <div id="phaser-canvas"></div>	</body></html>
Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
  • 4 weeks later...

Btw, there are other properties that are not copied from the json. For example Phaser.TilemapLayer is not copying opactiy and visible properties, so i had to make a dirty fix

var layer = this.map.createLayer(layerName, undefined, undefined, layerGroup);// @FIX not implemented - the 'alpha' and 'visible' inheritance, nor the 'name'layer.alpha = layer.layer.alpha;layer.visible = layer.layer.visible;layer.name = layer.layer.name;

Check out the source if you don't believe me :)



Ps: there are tons of such weird things (and bugs! btw), i've already got a "phaser-fix.js" with tons of overrides/extends, will push it to the repo later when i got time.

Link to comment
Share on other sites

  • 3 weeks later...

  • Recently Browsing   0 members

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