Skip to content

Commit 6f8759c

Browse files
committed
Whenever Camera.roundPixels was enabled it would use a bitwise operation to truncate the float (x |= 0) - this has been replaced across all files that used it, with a call to Math.round instead. This gives far better results when zooming cameras both in and out of a Scene, stopping thin gaps appearing between closely packed Game Objects.
1 parent 1467450 commit 6f8759c

14 files changed

Lines changed: 76 additions & 75 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
* `Graphics.stroke` is a new alias for the `strokePath` method, to keep the calls consistent with the Canvas Rendering Context API.
103103
* `Graphics.fill` is a new alias for the `fillPath` method, to keep the calls consistent with the Canvas Rendering Context API.
104104
* `LoaderPlugin.sceneManager` is a new property that is a reference to the global Scene Manager, useful for Plugins.
105+
* Whenever `Camera.roundPixels` was enabled it would use a bitwise operation to truncate the float (`x |= 0`) - this has been replaced across all files that used it, with a call to `Math.round` instead. This gives far better results when zooming cameras both in and out of a Scene, stopping thin gaps appearing between closely packed Game Objects.
105106

106107
### Bug Fixes
107108

src/cameras/2d/effects/Shake.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ var Shake = new Class({
270270

271271
if (this.camera.roundPixels)
272272
{
273-
this._offsetX |= 0;
274-
this._offsetY |= 0;
273+
this._offsetX = Math.round(this._offsetX);
274+
this._offsetY = Math.round(this._offsetY);
275275
}
276276
}
277277
else

src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
144144

145145
if (camera.roundPixels)
146146
{
147-
x |= 0;
148-
y |= 0;
147+
x = Math.round(x);
148+
y = Math.round(y);
149149
}
150150

151151
ctx.save();

src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextWebGLRenderer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,17 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, src, interpolationPerce
273273

274274
if (roundPixels)
275275
{
276-
tx0 |= 0;
277-
ty0 |= 0;
276+
tx0 = Math.round(tx0);
277+
ty0 = Math.round(ty0);
278278

279-
tx1 |= 0;
280-
ty1 |= 0;
279+
tx1 = Math.round(tx1);
280+
ty1 = Math.round(ty1);
281281

282-
tx2 |= 0;
283-
ty2 |= 0;
282+
tx2 = Math.round(tx2);
283+
ty2 = Math.round(ty2);
284284

285-
tx3 |= 0;
286-
ty3 |= 0;
285+
tx3 = Math.round(tx3);
286+
ty3 = Math.round(ty3);
287287
}
288288

289289
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);

src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
148148

149149
if (roundPixels)
150150
{
151-
x |= 0;
152-
y |= 0;
151+
x = Math.round(x);
152+
y = Math.round(y);
153153
}
154154

155155
ctx.save();

src/gameobjects/bitmaptext/static/BitmapTextWebGLRenderer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,17 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
203203

204204
if (roundPixels)
205205
{
206-
tx0 |= 0;
207-
ty0 |= 0;
206+
tx0 = Math.round(tx0);
207+
ty0 = Math.round(ty0);
208208

209-
tx1 |= 0;
210-
ty1 |= 0;
209+
tx1 = Math.round(tx1);
210+
ty1 = Math.round(ty1);
211211

212-
tx2 |= 0;
213-
ty2 |= 0;
212+
tx2 = Math.round(tx2);
213+
ty2 = Math.round(ty2);
214214

215-
tx3 |= 0;
216-
ty3 |= 0;
215+
tx3 = Math.round(tx3);
216+
ty3 = Math.round(ty3);
217217
}
218218

219219
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);

src/gameobjects/blitter/BlitterCanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, ca
7878
{
7979
if (roundPixels)
8080
{
81-
dx |= 0;
82-
dy |= 0;
81+
dx = Math.round(dx);
82+
dy = Math.round(dy);
8383
}
8484

8585
ctx.drawImage(

src/gameobjects/blitter/BlitterWebGLRenderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, cam
106106

107107
if (roundPixels)
108108
{
109-
tx0 |= 0;
110-
ty0 |= 0;
109+
tx0 = Math.round(tx0);
110+
ty0 = Math.round(ty0);
111111

112-
tx1 |= 0;
113-
ty1 |= 0;
112+
tx1 = Math.round(tx1);
113+
ty1 = Math.round(ty1);
114114
}
115115

116116
// TL x/y, BL x/y, BR x/y, TR x/y

src/gameobjects/mesh/MeshWebGLRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ var MeshWebGLRenderer = function (renderer, src, interpolationPercentage, camera
9292

9393
if (camera.roundPixels)
9494
{
95-
tx |= 0;
96-
ty |= 0;
95+
tx = Math.round(tx);
96+
ty = Math.round(ty);
9797
}
9898

9999
vertexViewF32[++vertexOffset] = tx;

src/gameobjects/particles/ParticleManagerCanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ var ParticleManagerCanvasRenderer = function (renderer, emitterManager, interpol
9999

100100
if (roundPixels)
101101
{
102-
x |= 0;
103-
y |= 0;
102+
x = Math.round(x);
103+
y = Math.round(y);
104104
}
105105

106106
ctx.drawImage(frame.source.image, cd.x, cd.y, cd.width, cd.height, x, y, cd.width, cd.height);

0 commit comments

Comments
 (0)