Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Parsing with getTile


Kyatt
 Share

Recommended Posts

Hello! I'm new to Phaser - I'm used to Flixel, so during this transition I'm alternating between having a really easy time with it and a baffling time with it. Right now, I'm trying to figure out how to parse sprites (ie: sweep a CSV and add an enemy/item anywhere that the value isn't 0). In Flixel, I was able to use the getTile(tx,ty) function to do this, but in Phaser, this function returns a tile instead of an integer. This is the parsing loop, more or less taken from my old Flixel code, that I have set up now:

itemsMap = game.add.tilemap(0,0,'itemsMap',true,16,16);items = game.add.group();for (var ty = 0; ty < 70; ty++)	for (var tx = 0; tx < 13; tx++)	{		if (itemsMap.getTile(tx, ty) != 0)			items.add(new Item(game, tx*16, ty*16, itemsMap.getTile(tx, ty)));	}

It will place the sprite in the right place, but it will be the wrong sprite - that 4th parameter in the Item constructor determines which sprite it is, and works correctly if I hard-code a number in there. Can someone please help me out here?

Link to comment
Share on other sites

The Tile object has an index property, this relates to the ID in the tilesheet that this Tile represents, so you could check that to place a sprite down. Also rather than loop through the map using getTile(x,y) you could use copy(). This will return an array of tile data matching the region given.

Tilemap.copy: function (x, y, width, height, layer)

Note in the above the values are in tiles, not pixels.

Link to comment
Share on other sites

  • 8 months later...
 Share

  • Recently Browsing   0 members

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