# How do I get the distance between 2 tilemap tiles?

0 favourites
• 2 posts
From the Asset Store
Piano tiles
\$9.99 USD
Template for a piano tiles game, fully documented in comments and video
• Imagine 9 pieces of grid paper placed in a 3x3 grid. Each piece of paper is a grid 300x400. Each piece of paper is actually a tilemap and they are all pinned to the center tilemap. If you drag the center tilemap off the screen there is a duplicate copy of the center tilemap (an "edge" tilemap) that is now on the screen (this makes for a continuously moveable map). On a touch end where you are not touching the center tilemap, the center tilemap is placed at the last touched "edge" tilemap location (the 8 "edge" tilemaps are still pinned and shift accordingly. This way you can scroll again and it will look seamless until you happen upon an "edge" tilemap.

The problem, each tilemap is labelled 0-300x,0-400y. When the map shifts the tilemap.positiontotileX,Y shifts as well. Which means on one click the distance formula works, but on the next click it shifts and gives the inverse.

I have no idea if any of this makes sense, but it's a huge pain.

The only other solution I can think to use would be to pin small sprites to the map used for starting distance and then just use a distance(pin.x,pin.y,touch.x,touch.y) {divided by the actual tile size). It should work, but seems inefficient.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• I usually go with these steps:

pinTileX = Tilemap.PositionToTileX(pin.X)

pinTileY = Tilemap.PositionToTileY(pin.Y)

touchTileX = Tilemap.PositionToTileX(Touch.X)

touchTileY = Tilemap.PositionToTileY(Touch.Y)

distance(Tilemap.TileToPositionX(pinTileX), Tilemap.TileToPositionY(pinTileY), Tilemap.TileToPositionX(touchTileX), Tilemap.TileToPositionY(touchTileY))

Hope it could help!

• 2 posts