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.

This commit is contained in:
Richard Davey 2018-11-30 10:27:25 +00:00
parent 146745057a
commit 6f8759c186
14 changed files with 76 additions and 75 deletions

View file

@ -102,6 +102,7 @@
* `Graphics.stroke` is a new alias for the `strokePath` method, to keep the calls consistent with the Canvas Rendering Context API.
* `Graphics.fill` is a new alias for the `fillPath` method, to keep the calls consistent with the Canvas Rendering Context API.
* `LoaderPlugin.sceneManager` is a new property that is a reference to the global Scene Manager, useful for Plugins.
* 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.
### Bug Fixes

View file

@ -270,8 +270,8 @@ var Shake = new Class({
if (this.camera.roundPixels)
{
this._offsetX |= 0;
this._offsetY |= 0;
this._offsetX = Math.round(this._offsetX);
this._offsetY = Math.round(this._offsetY);
}
}
else

View file

@ -144,8 +144,8 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
if (camera.roundPixels)
{
x |= 0;
y |= 0;
x = Math.round(x);
y = Math.round(y);
}
ctx.save();

View file

@ -273,17 +273,17 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, src, interpolationPerce
if (roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 |= 0;
ty2 |= 0;
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 |= 0;
ty3 |= 0;
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);

View file

@ -148,8 +148,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
if (roundPixels)
{
x |= 0;
y |= 0;
x = Math.round(x);
y = Math.round(y);
}
ctx.save();

View file

@ -203,17 +203,17 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
if (roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 |= 0;
ty2 |= 0;
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 |= 0;
ty3 |= 0;
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect);

View file

@ -78,8 +78,8 @@ var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, ca
{
if (roundPixels)
{
dx |= 0;
dy |= 0;
dx = Math.round(dx);
dy = Math.round(dy);
}
ctx.drawImage(

View file

@ -106,11 +106,11 @@ var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, cam
if (roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
}
// TL x/y, BL x/y, BR x/y, TR x/y

View file

@ -92,8 +92,8 @@ var MeshWebGLRenderer = function (renderer, src, interpolationPercentage, camera
if (camera.roundPixels)
{
tx |= 0;
ty |= 0;
tx = Math.round(tx);
ty = Math.round(ty);
}
vertexViewF32[++vertexOffset] = tx;

View file

@ -99,8 +99,8 @@ var ParticleManagerCanvasRenderer = function (renderer, emitterManager, interpol
if (roundPixels)
{
x |= 0;
y |= 0;
x = Math.round(x);
y = Math.round(y);
}
ctx.drawImage(frame.source.image, cd.x, cd.y, cd.width, cd.height, x, y, cd.width, cd.height);

View file

@ -118,17 +118,17 @@ var ParticleManagerWebGLRenderer = function (renderer, emitterManager, interpola
if (roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx1 |= 0;
ty1 |= 0;
tx2 |= 0;
ty2 |= 0;
tx3 |= 0;
ty3 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
var tint = getTint(particle.tint, alpha);

View file

@ -362,17 +362,17 @@ var ForwardDiffuseLightPipeline = new Class({
if (camera.roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 |= 0;
ty2 |= 0;
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 |= 0;
ty3 |= 0;
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
this.setTexture2D(texture, 0);

View file

@ -606,17 +606,17 @@ var TextureTintPipeline = new Class({
if (camera.roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 |= 0;
ty2 |= 0;
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 |= 0;
ty3 |= 0;
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
this.setTexture2D(texture, 0);
@ -971,17 +971,17 @@ var TextureTintPipeline = new Class({
if (camera.roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 |= 0;
ty2 |= 0;
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 |= 0;
ty3 |= 0;
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
this.setTexture2D(texture, 0);

View file

@ -661,17 +661,17 @@ var StaticTilemapLayer = new Class({
if (camera.roundPixels)
{
tx0 |= 0;
ty0 |= 0;
tx0 = Math.round(tx0);
ty0 = Math.round(ty0);
tx1 |= 0;
ty1 |= 0;
tx1 = Math.round(tx1);
ty1 = Math.round(ty1);
tx2 |= 0;
ty2 |= 0;
tx2 = Math.round(tx2);
ty2 = Math.round(ty2);
tx3 |= 0;
ty3 |= 0;
tx3 = Math.round(tx3);
ty3 = Math.round(ty3);
}
var vertexViewF32 = this.vertexViewF32[tilesetIndex];