Added Camera.roundPixels support, plus argument to 'follow' and setRoundPixels() method.

This commit is contained in:
photonstorm 2017-06-26 15:43:42 +01:00
parent 812197744f
commit 8b630c66b3
2 changed files with 27 additions and 7 deletions

View file

@ -8,7 +8,9 @@ var Camera = function (x, y, width, height)
this.width = width;
this.height = height;
this.roundPixels = false;
this.useBounds = false;
this._bounds = new Rectangle();
this.scrollX = 0.0;
@ -129,7 +131,7 @@ Camera.prototype = {
}
},
startFollow: function (gameObjectOrPoint)
startFollow: function (gameObjectOrPoint, roundPx)
{
if (this._follow !== null)
{
@ -137,6 +139,11 @@ Camera.prototype = {
}
this._follow = gameObjectOrPoint;
if (roundPx !== undefined)
{
this.roundPixels = roundPx;
}
},
stopFollow: function ()
@ -145,6 +152,13 @@ Camera.prototype = {
this._follow = null;
},
setRoundPixels: function (value)
{
this.roundPixels = value;
return this;
},
flash: function (duration, red, green, blue, force)
{
if (!force && this._flashAlpha > 0.0)
@ -218,7 +232,7 @@ Camera.prototype = {
var originY = height / 2;
var follow = this._follow;
if (follow != null)
if (follow !== null)
{
originX = follow.x;
originY = follow.y;
@ -235,18 +249,18 @@ Camera.prototype = {
var boundsR = Math.max(bounds.right - width, width);
var boundsB = Math.max(bounds.bottom - height, height);
if (this.scrollX < bounds.x)
if (this.scrollX < boundsX)
{
this.scrollX = bounds.x;
this.scrollX = boundsX;
}
if (this.scrollX > boundsR)
{
this.scrollX = boundsR;
}
if (this.scrollY < bounds.y)
if (this.scrollY < boundsY)
{
this.scrollY = bounds.y;
this.scrollY = boundsY;
}
if (this.scrollY > boundsB)
{
@ -254,6 +268,12 @@ Camera.prototype = {
}
}
if (this.roundPixels)
{
this.scrollX = Math.round(this.scrollX);
this.scrollY = Math.round(this.scrollY);
}
matrix.loadIdentity();
matrix.translate(this.x + originX, this.y + originY);
matrix.rotate(this.rotation);

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '541299d0-5a78-11e7-bceb-fd404c07e0b9'
build: 'adb03e70-5a7d-11e7-8ee9-f7ee67d93c13'
};
module.exports = CHECKSUM;