Kyatt Posted November 3, 2013 Share Posted November 3, 2013 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 More sharing options...
rich Posted November 3, 2013 Share Posted November 3, 2013 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 More sharing options...
beancoder Posted July 24, 2014 Share Posted July 24, 2014 I want to get the tile number from the user input coordinates!I want to detect the tile number from where the mouse points to.. Can I do that? Something like getTileNumber(input.x,input.y); Please help Link to comment Share on other sites More sharing options...
marvster Posted July 24, 2014 Share Posted July 24, 2014 Each Tile has an index, which represent the tiletype of map data.So why not going to:Tilemap.getTile(x, y, true).index //nonNull = true will create a TIle object with index -1, if no tile was found on x,yIf you want to create enemies, npc, stuff etc from Tilemap data, have look at Tilemap.createFromObjects Link to comment Share on other sites More sharing options...
Recommended Posts