Skip to content

Commit d01636b

Browse files
committed
Fix sub-pixel jitter after tile separation
1 parent a996562 commit d01636b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/physics/arcade/tilemap/ProcessTileSeparationX.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ var ProcessTileSeparationX = function (body, x)
2727
}
2828

2929
body.position.x -= x;
30+
31+
// Float arithmetic can leave position at e.g. 63.9997, causing 1px
32+
// jitter. Snap near-integer results but preserve intentionally
33+
// fractional positions (non-integer body sizes from scaled sprites).
34+
var rx = Math.round(body.position.x);
35+
36+
if (Math.abs(body.position.x - rx) < 0.01)
37+
{
38+
body.position.x = rx;
39+
}
40+
3041
body.updateCenter();
3142

3243
if (body.bounce.x === 0)

src/physics/arcade/tilemap/ProcessTileSeparationY.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ var ProcessTileSeparationY = function (body, y)
2727
}
2828

2929
body.position.y -= y;
30+
31+
// Float arithmetic can leave position at e.g. 63.9997, causing 1px
32+
// jitter. Snap near-integer results but preserve intentionally
33+
// fractional positions (non-integer body sizes from scaled sprites).
34+
var ry = Math.round(body.position.y);
35+
36+
if (Math.abs(body.position.y - ry) < 0.01)
37+
{
38+
body.position.y = ry;
39+
}
40+
3041
body.updateCenter();
3142

3243
if (body.bounce.y === 0)

0 commit comments

Comments
 (0)