How do I get the nearest tilemap position?

0 favourites
  • 2 posts
  • Hi,

    There are a lot of tilemap on the map, when I touch any empty space, I can get the touch.X and touch.Y very easily.

    but I want to get the tilemap(X and Y) near to touch.X and touch.Y. How to do that?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is one solutions (didn't test it)

    Let's say your tiles are 50x50px

    You click on a spot somewhere - let's take 205, 140

    You could store this values in a variable and now do a little bit of math (here I call the variable vX and vY)

    floor (vX / 50) * 50 and the same but with vY

    floor just round the number down, so the result would tell you wich tile it is and so if multiplied by the tile size you get the position of the tile. If the origin point is not on the top left but in the center you would need to add 25 to your calculation.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)