# Is there a way to check the distance between a Sprite and a tile on my tilemap?

**URL:** <https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342>\
**Category:** Help\
**Created:** [November 10, 2025, 3:27am UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342 "2025-11-10T03:27:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spike](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/spike/32/33316_2.png) [@Spike](https://forum.makecode.com/u/Spike)\
**Post date:** [November 10, 2025, 3:27am UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/1 "2025-11-10T03:27:31Z")

</div>

Okay, so do you know how there is a “distance between (mySprite) and (myEnemy)” block in the Sprite Utils extension?

Is there a way to check the distance between a sprite and a tile on my tilemap?

If you want context I’m trying to make it so that when the player gets close to a tile (named “Enemy No1”) it will disappear.

Link: [https://arcade.makecode.com/S19264-25048-33875-60970](https://arcade.makecode.com/S19264-25048-33875-60970)

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [November 10, 2025, 3:28am UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/2 "2025-11-10T03:28:31Z")

</div>

The simplest way, without creating a new extension, is to place a sprite on that tile.

---

<div class="post-metadata">

**Author:** ![Spike](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/spike/32/33316_2.png) [@Spike](https://forum.makecode.com/u/Spike)\
**Post date:** [November 12, 2025, 5:53pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/3 "2025-11-12T17:53:37Z")

</div>

How do I do that?

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [November 12, 2025, 7:13pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/4 "2025-11-12T19:13:17Z")

</div>

How do you place a sprite on a tilemap? One of these two blocks should suit your needs:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/d/c/dc2c53942505087014eae49cb60124e96927d55e.png)

---

<div class="post-metadata">

**Author:** ![Bifrosty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bifrosty/32/24819_2.png) [@Bifrosty](https://forum.makecode.com/u/Bifrosty)\
**Post date:** [November 12, 2025, 9:13pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/5 "2025-11-12T21:13:21Z")

</div>

Copy this function:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/b/e/be51a3c4cf9d24241b9ec9c28c54ecee0ae2615b.png)

---

<div class="post-metadata">

**Author:** ![JtSpeedRun](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jtspeedrun/32/33167_2.png) [@JtSpeedRun](https://forum.makecode.com/u/JtSpeedRun)\
**Post date:** [November 13, 2025, 6:24pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/6 "2025-11-13T18:24:52Z")

</div>

This is a really helpful function. I’ve been meaning to ask if there was a sprite-less way to do this for awhile. Is there a way to do this with specific tile graphics instead of just tile columns amd rows?

Like a function that can tell you how close a certain tile graphic, if that makes sense. But thanks none the less, i’ll be messing around with this code

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [November 13, 2025, 10:47pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/7 "2025-11-13T22:47:04Z")

</div>

My good sir, there is a sprite-less way to make sprites! It’s all just math and more math. By “specific tile graphics” do you mean a sort of “distance to nearest tile of type” block?  
You could get the “specific columns and rows” from the tiles in a “array of tiles of type” block with that little “(location) [column]” block and put them all through this function to find the one that’s closest.

---

<div class="post-metadata">

**Author:** ![JtSpeedRun](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jtspeedrun/32/33167_2.png) [@JtSpeedRun](https://forum.makecode.com/u/JtSpeedRun)\
**Post date:** [November 13, 2025, 10:58pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/8 "2025-11-13T22:58:03Z")

</div>

Yes, something exactly like that

---

<div class="post-metadata">

**Author:** ![Bifrosty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bifrosty/32/24819_2.png) [@Bifrosty](https://forum.makecode.com/u/Bifrosty)\
**Post date:** [November 14, 2025, 12:56am UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/9 "2025-11-14T00:56:21Z")

</div>

Yes, that’s pretty easy to adjust. In the scene drawer there is an “array of all [insert tile] locations” This is a list of every location of a tile. It acts just like any other array. You can use this to gather information about a tile in order to make it usable with the function.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/4/b/4b8e11cc8cdd4b2d32af5ded8f5d5e9cb54e8461.png)

Note that you would need to adjust it’s numbers if you were working with a different tile size.

If you want to play around with the function you should check out the Pythagorean Theorem:

 ![images](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/e/7/e732aaf428d206656a32c261c553a3aa5a01b0c5.png)  
It is kinda the root of all math–like most of it lol.

---

<div class="post-metadata">

**Author:** ![MasonTheLitten](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/masonthelitten/32/24867_2.png) [@MasonTheLitten](https://forum.makecode.com/u/MasonTheLitten)\
**Post date:** [February 20, 2026, 8:14pm UTC](https://forum.makecode.com/t/is-there-a-way-to-check-the-distance-between-a-sprite-and-a-tile-on-my-tilemap/40342/10 "2026-02-20T20:14:03Z")

</div>

is there a way for us to use this function for multiple tiles?  
Like for example, you want to detect if a certain tile is next to a sprite, and each different tile type, it has its own data.
