Jump to content

Tilemap.getTileWorldXY always returns undefined


ghostrifle
 Share

Recommended Posts

Hey there again,

 

I've got a strange problem with Tilemap.getTileWorldXY. The tilemap, collision against the map etc is working. But when I want to get a tile via getTileWorldXY , I'm always getting undefined.

 

Here's the code for creating the tilemap and the layer:

map = game.add.tilemap('current_level');      map.addTilesetImage('tiles', 'tiles');      // the gray tiles shall be responsible for collisions, check the tiles.png, the first one is the gray one      map.setCollisionBetween(0, 1);      // loading the layer from the tilemap, the layer name got defines in the Tiled editor      map_layer = map.createLayer('Level');      map_layer.resizeWorld();      map_layer.debug = true; // show the bounding boxes for collisions

and here's the call to get the tile

map.getTileWorldXY(game.input.x, player.y,map_layer);

No matter which coordinates I'm using for getTileWorldXY, it won't work.

Link to comment
Share on other sites

  • 7 months later...

I know this post is more than 6 months old, but I have the same question... how to get getTileWorldXY to work properly.  My approach is same as the original post, but I'm not getting good data back.  My need is to be able to identify the tile ID that the player character is standing on at any time, and take appropriate actions if needed.

 

Many thanks if you can help.

 

Link to comment
Share on other sites

  • 5 months later...

i know this is a bit stale of a thread, but I ran into this issue, and after a bit of tweeking I seem to have gotten this kinda sorta right?

 

NOTE: THIS MAY OR MAY NOT ACTUALLY BE CORRECT! DO NOT HOLD ME TO IT!

 

I managed to get it to work well enough in console with a simple function:

 

function test2(){
console.log(map.getTileWorldXY(player.body.x, player.body.y,32,32, layer));
}
 
where:
map = game.add.tilemap('tilemap');
layer = map.createLayer('floor');
player = game.add.sprite(playerX, playerY, 'walker');
 
When I call the function standing on anywhere on my tilemap that has a tile on the 'floor' layer, it returns a json object containing the tile I am standing on, if I am on that layer, else it is returning null.
 
Hope this is a bit helpful, hate being OP's position, kinda reminded me of https://xkcd.com/979/
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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