# Faster way to get overlaping sprites?

**URL:** <https://forum.makecode.com/t/faster-way-to-get-overlaping-sprites/11598>\
**Category:** Help\
**Created:** [January 4, 2022, 12:10am UTC](https://forum.makecode.com/t/faster-way-to-get-overlaping-sprites/11598 "2022-01-04T00:10:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [January 4, 2022, 12:10am UTC](https://forum.makecode.com/t/faster-way-to-get-overlaping-sprites/11598/1 "2022-01-04T00:10:53Z")

</div>

Is there any way to get a sprite that is overlapping with a sprite of a kind that’s faster then this:

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/38dd9a8d449efa706ddcc90e6c344a06b95ff242.png)

Does Arcade keep track of “overlapping” sprites on sprites somewhere so that we don’t have to iterate over every other sprite to see if it’s overlapping with it? Like maybe a private list of sprites?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [January 4, 2022, 12:23am UTC](https://forum.makecode.com/t/faster-way-to-get-overlaping-sprites/11598/2 "2022-01-04T00:23:14Z")

</div>

Unfortunately there is no faster way to do this that isn’t very hacky…

We do keep this information around in the physics engine, it just isn’t accessible from outside. You can see where it’s declared [here](https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/physics.ts#L53) (note the `protected`). The actual implementation is here:

> <https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/spritemap.ts>

Of course `protected` is more of a “suggestion” in makecode than it is a rule, so you could do this:

```auto
function getOverlappingByKind(sprite: Sprite, kind: number) {
    // EVIL CODE
    const map = (game.currentScene().physicsEngine as any).map as sprites.SpriteMap;

    return map.neighbors(sprite).filter(s => s.kind() === kind).filter(s => s.overlapsWith(sprite));
}

```

but you _should not_ do that because it could break at any time.
