Jump to content

How to get sprite(player) position in terms of coordinates


Ashish
 Share

Recommended Posts

I am trying to create a game  where I have created one player and at the background I have added tiled map. The problem is how can I get the player coordinate every time so that I can replace the tiles covered by the player. Thank you !

Link to comment
Share on other sites

Could you please elaborate a little more? Any more information or just make your first post make more sense please lol

What I kind of got from that is that you have a player and a tiled map ABOVE the player, and you want the players tiled coordinates so you can remove the tile ABOVE the player (so you can see the player). I might be wrong to what you mean bc idrk what you were trying to say in the post above. But, if that is what you were trying to say, there is no need to do that since you can just move the player sprite to show up above the tiled layer. If you are having the problem i described, you most likely defiened the tiled layer after you defined the sprite?

If that wasnt your problem and want to just find out what tiled coordinate the player is at, you can do something like this:

tiledX = Math.round(player.x/(the width of a tile in your tiled map));

tiledY = Math.round(player.y/(the height of a tile in your tiled map));

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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