# \[BUG\] rounding error when rendering sprites

**URL:** https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458
**Category:** Help
**Created:** [August 18, 2026, 10:06pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458 "2026-08-18T22:06:43Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 18, 2026, 10:06pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/1 "2026-08-18T22:06:43Z")

</div>

![ezgif-83fc3a8441e4f2a9](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/e/4/e45c4372d271001a72ca057d0b9a5d74c9b375d2.gif)

@richard , I think the sprite’s rendering is using the wrong rounding (Its using `x|0` but I think it needs to use `Math.round(x),`or the opposite for collisions), and it creates that bug. On a wall facing right, the player goes through it. On the wall facing left, the player walks on the air.

(the video quality is bad bc it’s a gif)

---

<div class="post-metadata">

### Author: ![YamJam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yamjam/32/29681_2.png) [@YamJam](https://forum.makecode.com/u/YamJam)
#### Post date: [August 19, 2026, 7:05pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/2 "2026-08-19T19:05:21Z")

</div>

What exactly does that mean? I know this is like galaxies too ahead of my level, but it sounds interesting and I want to know.

---

<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: [August 19, 2026, 7:05pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/3 "2026-08-19T19:05:43Z")

</div>

nope, this is intended. we don’t use round because it’s slower

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 20, 2026, 2:36am UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/4 "2026-08-20T02:36:44Z")

</div>

looked at the code a little bit, and `(v + 128) >> 8` rounds the number:

> <https://github.com/microsoft/pxt-common-packages/blob/f4f92f1cd9f146092da6e2246216398010aece65/libs/base/fixed.ts#L75>

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 20, 2026, 4:45pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/5 "2026-08-20T16:45:02Z")

</div>

@AlexK edit (forgot “rounds”):

looked at the code a little bit, and `(v + 128) >> 8` rounds the number:

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 24, 2026, 4:58pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/6 "2026-08-24T16:58:43Z")

</div>

um @richard i think in the simulator, Math.floor is actually the tiniest bit faster (or at least on some js engines).

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [August 24, 2026, 5:24pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/7 "2026-08-24T17:24:38Z")

</div>

(oops i accidentaly replied to YamJam)

---

<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: [August 24, 2026, 10:59pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/8 "2026-08-24T22:59:25Z")

</div>

It needs to be faster on hardware, and bitwise ops are definitely the fastest there.

---

<div class="post-metadata">

### Author: ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)
#### Post date: [September 19, 2026, 7:47pm UTC](https://forum.makecode.com/t/bug-rounding-error-when-rendering-sprites/45458/9 "2026-09-19T19:47:33Z")

</div>

maybe use shims? That makes the most sense because you could have the js version use Math.floor, and the cpp version use bitwise ops
