Skip to content

Commit 8b630c6

Browse files
committed
Added Camera.roundPixels support, plus argument to 'follow' and setRoundPixels() method.
1 parent 8121977 commit 8b630c6

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

v3/src/camera/Camera.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ var Camera = function (x, y, width, height)
88
this.width = width;
99
this.height = height;
1010

11+
this.roundPixels = false;
1112
this.useBounds = false;
13+
1214
this._bounds = new Rectangle();
1315

1416
this.scrollX = 0.0;
@@ -129,14 +131,19 @@ Camera.prototype = {
129131
}
130132
},
131133

132-
startFollow: function (gameObjectOrPoint)
134+
startFollow: function (gameObjectOrPoint, roundPx)
133135
{
134136
if (this._follow !== null)
135137
{
136138
this.stopFollow();
137139
}
138140

139141
this._follow = gameObjectOrPoint;
142+
143+
if (roundPx !== undefined)
144+
{
145+
this.roundPixels = roundPx;
146+
}
140147
},
141148

142149
stopFollow: function ()
@@ -145,6 +152,13 @@ Camera.prototype = {
145152
this._follow = null;
146153
},
147154

155+
setRoundPixels: function (value)
156+
{
157+
this.roundPixels = value;
158+
159+
return this;
160+
},
161+
148162
flash: function (duration, red, green, blue, force)
149163
{
150164
if (!force && this._flashAlpha > 0.0)
@@ -218,7 +232,7 @@ Camera.prototype = {
218232
var originY = height / 2;
219233
var follow = this._follow;
220234

221-
if (follow != null)
235+
if (follow !== null)
222236
{
223237
originX = follow.x;
224238
originY = follow.y;
@@ -235,25 +249,31 @@ Camera.prototype = {
235249
var boundsR = Math.max(bounds.right - width, width);
236250
var boundsB = Math.max(bounds.bottom - height, height);
237251

238-
if (this.scrollX < bounds.x)
252+
if (this.scrollX < boundsX)
239253
{
240-
this.scrollX = bounds.x;
254+
this.scrollX = boundsX;
241255
}
242256
if (this.scrollX > boundsR)
243257
{
244258
this.scrollX = boundsR;
245259
}
246260

247-
if (this.scrollY < bounds.y)
261+
if (this.scrollY < boundsY)
248262
{
249-
this.scrollY = bounds.y;
263+
this.scrollY = boundsY;
250264
}
251265
if (this.scrollY > boundsB)
252266
{
253267
this.scrollY = boundsB;
254268
}
255269
}
256270

271+
if (this.roundPixels)
272+
{
273+
this.scrollX = Math.round(this.scrollX);
274+
this.scrollY = Math.round(this.scrollY);
275+
}
276+
257277
matrix.loadIdentity();
258278
matrix.translate(this.x + originX, this.y + originY);
259279
matrix.rotate(this.rotation);

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '541299d0-5a78-11e7-bceb-fd404c07e0b9'
2+
build: 'adb03e70-5a7d-11e7-8ee9-f7ee67d93c13'
33
};
44
module.exports = CHECKSUM;

0 commit comments

Comments
 (0)