# Sprite collisions with a colour?

**URL:** <https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255>\
**Category:** Help\
**Tags:** game\
**Created:** [December 5, 2024, 11:47pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255 "2024-12-05T23:47:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingkk0310](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kingkk0310/32/17981_2.png) [@kingkk0310](https://forum.makecode.com/u/kingkk0310)\
**Post date:** [December 5, 2024, 11:47pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/1 "2024-12-05T23:47:38Z")

</div>

i was trying to make a pacman clone, but the walls were thinner than a tile so i couldnt use the built in walls feature, is there any wayt o make it collide with the blue colour?

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

---

<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:** [December 5, 2024, 11:49pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/2 "2024-12-05T23:49:17Z")

</div>

we don’t have any support for that, but you could try coding it yourself! not trivial though.

instead, you could try using tilemaps with 8x8 tiles instead of 16x16 tiles to make your walls thinner. add the arcade-tile-util extension to get access to 8x8 tilemaps

---

<div class="post-metadata">

**Author:** ![redSprite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/redsprite/32/34262_2.png) [@redSprite](https://forum.makecode.com/u/redSprite)\
**Post date:** [December 6, 2024, 5:41pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/3 "2024-12-06T17:41:58Z")

</div>

But what if we want custom tile sizes?

---

<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:** [December 6, 2024, 5:59pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/4 "2024-12-06T17:59:49Z")

</div>

@redSprite the only tile sizes supported by MakeCode are ones where the side length is a power of 2. So 4x4, 8x8, 16x16, 32x32 are all supported (though we have only surfaced 8x8 and 16x16)

we have this restriction in place for performance reasons, when converting between x/y sprite coordinates to column/row tile coordinates you need to divide the x/y values by whatever the width of the tile is. division is _slow_ on hardware, especially when floating point numbers are involved.

however, there is actually a trick to doing division when the divisor is a power of 2. because numbers are stored in binary on computers, you can divide and multiply numbers by powers of 2 using bitshifting. bitshifting is a super fast operation compared to division and multiplication!

for example, say we have the number 13. in binary, 13 is written as `00001101`

if we shift all of the bits to the left, we get this:

```auto
00001101 << 1 = 00011010 = 26

```

if we shift all of the bits to the right, we get this:

```auto
00001101 >> 1 = 00000110 = 6

```

so shifting left is the same as multiplying by 2 and shifting right is the same as dividing by 2 (but the remainder gets cut off, which doesn’t matter for our purposes).

let’s look at another example: say we have a sprite at the coordinates x=50, y=37 and we want to figure out which tile column and row they are on in a tilemap with 8x8 tiles. 8 is equal to 2^3, so if we bitshift right by 3 we can divide by 8

```auto
// x = 50
00110010 >> 3 = 00000110 = 6

// y = 37
00100101 >> 3 = 00000100 = 4

```

so we know that this sprite is on the tile in column 6 and row 4

---

<div class="post-metadata">

**Author:** ![redSprite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/redsprite/32/34262_2.png) [@redSprite](https://forum.makecode.com/u/redSprite)\
**Post date:** [December 6, 2024, 6:15pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/5 "2024-12-06T18:15:17Z")

</div>

Noice

---

<div class="post-metadata">

**Author:** ![Sonicblaston](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sonicblaston/32/19164_2.png) [@Sonicblaston](https://forum.makecode.com/u/Sonicblaston)\
**Post date:** [December 10, 2024, 11:04pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/6 "2024-12-10T23:04:39Z")

</div>

Would it be possible to make tiles 20x20?

---

<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:** [December 11, 2024, 10:36pm UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/7 "2024-12-11T22:36:05Z")

</div>

@Sonicblaston that’s not a power of 2, so no not today

---

<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:** [December 12, 2024, 12:00am UTC](https://forum.makecode.com/t/sprite-collisions-with-a-colour/32255/8 "2024-12-12T00:00:18Z")

</div>

> [@richard](#):
>
> we don’t have any support for that, but you could try coding it yourself! not trivial though.

I don’t see the problem with just coding it yourself! You can use the Color At block

 ![IMG_6691](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/5/4/5412b53432fc754dc0002e29724f5fcba2c33f45.jpeg)  
to detect the color in front of Packman, depending on which direction it’s moving, and stop it if the color one pixel ahead of Packman is the blue color!  
Personally, I would code a sort of grid system into this so that I could deal with that instead of all the sprite color detection stuff, but you do you!
