[BUG] rounding error when rendering sprites

ezgif-83fc3a8441e4f2a9

@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)

6 Likes

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.

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

2 Likes

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

@AlexK edit (forgot “rounds”):

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

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

1 Like

(oops i accidentaly replied to YamJam)

1 Like

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

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