How do I get the nearest tilemap position?

Get help using Construct 2

Post » Sun Mar 06, 2016 1:27 pm

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?
Posts: 13
Reputation: 576

Post » Sun Mar 06, 2016 1:59 pm

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.

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
Posts: 340
Reputation: 4,707

Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, jorgmaquoi, maxwell88, TELLES0808 and 9 guests