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

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

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

How do I do that?

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

Copy this function:

3 Likes

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

2 Likes

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.

1 Like

Yes, something exactly like that

1 Like

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.

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:


It is kinda the root of all math–like most of it lol.

2 Likes