diff --git a/Phaser/gameobjects/ScrollRegion.ts b/Phaser/gameobjects/ScrollRegion.ts
index 97ff5404..4f8370f6 100644
--- a/Phaser/gameobjects/ScrollRegion.ts
+++ b/Phaser/gameobjects/ScrollRegion.ts
@@ -15,16 +15,13 @@ module Phaser {
constructor(x: number, y: number, width: number, height: number, speedX:number, speedY:number) {
// Our seamless scrolling quads
- this._A = new Quad(0, 0, width, height);
- this._B = new Quad();
- this._C = new Quad();
- this._D = new Quad();
-
+ this._A = new Quad(x, y, width, height);
+ this._B = new Quad(x, y, width, height);
+ this._C = new Quad(x, y, width, height);
+ this._D = new Quad(x, y, width, height);
this._scroll = new MicroPoint();
- this._offset = new MicroPoint(x, y);
-
+ this._bounds = new Quad(x, y, width, height);
this.scrollSpeed = new MicroPoint(speedX, speedY);
- this.bounds = new Quad(0, 0, width, height);
}
@@ -33,59 +30,58 @@ module Phaser {
private _C: Quad;
private _D: Quad;
+ private _bounds: Quad;
private _scroll: MicroPoint;
- private _offset: MicroPoint;
private _anchorWidth: number = 0;
private _anchorHeight: number = 0;
private _inverseWidth: number = 0;
private _inverseHeight: number = 0;
- public bounds: Quad;
public visible: bool = true;
public scrollSpeed: MicroPoint;
public update(delta: number) {
- this._scroll.x = Math.round(this._scroll.x + (this.scrollSpeed.x));
- this._scroll.y = Math.round(this._scroll.y + (this.scrollSpeed.y));
+ this._scroll.x += this.scrollSpeed.x;
+ this._scroll.y += this.scrollSpeed.y;
- if (this._scroll.x > this._offset.x + this.bounds.width)
+ if (this._scroll.x > this._bounds.right)
{
- this._scroll.x = this._offset.x;
+ this._scroll.x = this._bounds.x;
}
- if (this._scroll.x < this._offset.x)
+ if (this._scroll.x < this._bounds.x)
{
- this._scroll.x = this._offset.x + this.bounds.width;
+ this._scroll.x = this._bounds.right;
}
- if (this._scroll.y > this._offset.y + this.bounds.height)
+ if (this._scroll.y > this._bounds.bottom)
{
- this._scroll.y = this._offset.y;
+ this._scroll.y = this._bounds.y;
}
- if (this._scroll.y < this._offset.y)
+ if (this._scroll.y < this._bounds.y)
{
- this._scroll.y = this._offset.y + this.bounds.height;
+ this._scroll.y = this._bounds.bottom;
}
// Anchor Dimensions
- this._anchorWidth = this.bounds.width - this._scroll.x;
- this._anchorHeight = this.bounds.height - this._scroll.y;
+ this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
+ this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
- if (this._anchorWidth > this.bounds.width)
+ if (this._anchorWidth > this._bounds.width)
{
- this._anchorWidth = this.bounds.width;
+ this._anchorWidth = this._bounds.width;
}
- if (this._anchorHeight > this.bounds.height)
+ if (this._anchorHeight > this._bounds.height)
{
- this._anchorHeight = this.bounds.height;
+ this._anchorHeight = this._bounds.height;
}
- this._inverseWidth = this.bounds.width - this._anchorWidth;
- this._inverseHeight = this.bounds.height - this._anchorHeight;
+ this._inverseWidth = this._bounds.width - this._anchorWidth;
+ this._inverseHeight = this._bounds.height - this._anchorHeight;
// Quad A
this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
@@ -113,11 +109,21 @@ module Phaser {
return;
}
+ // dx/dy are the world coordinates to render the FULL ScrollZone into.
+ // This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
+
this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
+ //context.fillStyle = 'rgb(255,255,255)';
+ //context.font = '18px Arial';
+ //context.fillText('QuadA: ' + this._A.toString(), 32, 450);
+ //context.fillText('QuadB: ' + this._B.toString(), 32, 480);
+ //context.fillText('QuadC: ' + this._C.toString(), 32, 510);
+ //context.fillText('QuadD: ' + this._D.toString(), 32, 540);
+
}
private crop(context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
@@ -135,6 +141,13 @@ module Phaser {
srcH = (destY + destH) - offsetY;
}
+ srcX = Math.floor(srcX);
+ srcY = Math.floor(srcY);
+ srcW = Math.floor(srcW);
+ srcH = Math.floor(srcH);
+ offsetX = Math.floor(offsetX + this._bounds.x);
+ offsetY = Math.floor(offsetY + this._bounds.y);
+
if (srcW > 0 && srcH > 0)
{
context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
diff --git a/Phaser/gameobjects/ScrollZone.ts b/Phaser/gameobjects/ScrollZone.ts
index 7d4094ed..75921852 100644
--- a/Phaser/gameobjects/ScrollZone.ts
+++ b/Phaser/gameobjects/ScrollZone.ts
@@ -64,6 +64,12 @@ module Phaser {
public addRegion(x: number, y: number, width: number, height: number, speedX?:number = 0, speedY?:number = 0):ScrollRegion {
+ if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height)
+ {
+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
+ return;
+ }
+
this.currentRegion = new ScrollRegion(x, y, width, height, speedX, speedY);
this.regions.push(this.currentRegion);
@@ -79,6 +85,8 @@ module Phaser {
this.currentRegion.scrollSpeed.setTo(x, y);
}
+ return this;
+
}
public update() {
diff --git a/Phaser/geom/Quad.ts b/Phaser/geom/Quad.ts
index 45e889a1..88adc41d 100644
--- a/Phaser/geom/Quad.ts
+++ b/Phaser/geom/Quad.ts
@@ -82,6 +82,17 @@ module Phaser {
}
+ /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ public toString(): string {
+
+ return "[{Quad (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + ")}]";
+
+ }
+
}
}
\ No newline at end of file
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index f1fd2fdb..7b988313 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -111,6 +111,10 @@
parallax.ts
+
+
+ region demo.ts
+
scroll window.ts
diff --git a/Tests/assets/pics/game14_angel_dawn.png b/Tests/assets/pics/game14_angel_dawn.png
index 146cb952..3d91158a 100644
Binary files a/Tests/assets/pics/game14_angel_dawn.png and b/Tests/assets/pics/game14_angel_dawn.png differ
diff --git a/Tests/phaser.js b/Tests/phaser.js
index 150af5fe..e31ef067 100644
--- a/Tests/phaser.js
+++ b/Tests/phaser.js
@@ -11581,6 +11581,14 @@ var Phaser;
if (typeof t === "undefined") { t = 0; }
return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t);
};
+ Quad.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return "[{Quad (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + ")}]";
+ };
return Quad;
})();
Phaser.Quad = Quad;
@@ -11603,41 +11611,40 @@ var Phaser;
this._inverseHeight = 0;
this.visible = true;
// Our seamless scrolling quads
- this._A = new Phaser.Quad(0, 0, width, height);
- this._B = new Phaser.Quad();
- this._C = new Phaser.Quad();
- this._D = new Phaser.Quad();
+ this._A = new Phaser.Quad(x, y, width, height);
+ this._B = new Phaser.Quad(x, y, width, height);
+ this._C = new Phaser.Quad(x, y, width, height);
+ this._D = new Phaser.Quad(x, y, width, height);
this._scroll = new Phaser.MicroPoint();
- this._offset = new Phaser.MicroPoint(x, y);
+ this._bounds = new Phaser.Quad(x, y, width, height);
this.scrollSpeed = new Phaser.MicroPoint(speedX, speedY);
- this.bounds = new Phaser.Quad(0, 0, width, height);
}
ScrollRegion.prototype.update = function (delta) {
- this._scroll.x = Math.round(this._scroll.x + (this.scrollSpeed.x));
- this._scroll.y = Math.round(this._scroll.y + (this.scrollSpeed.y));
- if(this._scroll.x > this._offset.x + this.bounds.width) {
- this._scroll.x = this._offset.x;
+ this._scroll.x += this.scrollSpeed.x;
+ this._scroll.y += this.scrollSpeed.y;
+ if(this._scroll.x > this._bounds.right) {
+ this._scroll.x = this._bounds.x;
}
- if(this._scroll.x < this._offset.x) {
- this._scroll.x = this._offset.x + this.bounds.width;
+ if(this._scroll.x < this._bounds.x) {
+ this._scroll.x = this._bounds.right;
}
- if(this._scroll.y > this._offset.y + this.bounds.height) {
- this._scroll.y = this._offset.y;
+ if(this._scroll.y > this._bounds.bottom) {
+ this._scroll.y = this._bounds.y;
}
- if(this._scroll.y < this._offset.y) {
- this._scroll.y = this._offset.y + this.bounds.height;
+ if(this._scroll.y < this._bounds.y) {
+ this._scroll.y = this._bounds.bottom;
}
// Anchor Dimensions
- this._anchorWidth = this.bounds.width - this._scroll.x;
- this._anchorHeight = this.bounds.height - this._scroll.y;
- if(this._anchorWidth > this.bounds.width) {
- this._anchorWidth = this.bounds.width;
+ this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
+ this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
+ if(this._anchorWidth > this._bounds.width) {
+ this._anchorWidth = this._bounds.width;
}
- if(this._anchorHeight > this.bounds.height) {
- this._anchorHeight = this.bounds.height;
+ if(this._anchorHeight > this._bounds.height) {
+ this._anchorHeight = this._bounds.height;
}
- this._inverseWidth = this.bounds.width - this._anchorWidth;
- this._inverseHeight = this.bounds.height - this._anchorHeight;
+ this._inverseWidth = this._bounds.width - this._anchorWidth;
+ this._inverseHeight = this._bounds.height - this._anchorHeight;
// Quad A
this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
// Quad B
@@ -11656,11 +11663,19 @@ var Phaser;
if(this.visible == false) {
return;
}
+ // dx/dy are the world coordinates to render the FULL ScrollZone into.
+ // This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
- };
+ //context.fillStyle = 'rgb(255,255,255)';
+ //context.font = '18px Arial';
+ //context.fillText('QuadA: ' + this._A.toString(), 32, 450);
+ //context.fillText('QuadB: ' + this._B.toString(), 32, 480);
+ //context.fillText('QuadC: ' + this._C.toString(), 32, 510);
+ //context.fillText('QuadD: ' + this._D.toString(), 32, 540);
+ };
ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
offsetX += destX;
offsetY += destY;
@@ -11670,6 +11685,12 @@ var Phaser;
if(srcH > (destY + destH) - offsetY) {
srcH = (destY + destH) - offsetY;
}
+ srcX = Math.floor(srcX);
+ srcY = Math.floor(srcY);
+ srcW = Math.floor(srcW);
+ srcH = Math.floor(srcH);
+ offsetX = Math.floor(offsetX + this._bounds.x);
+ offsetY = Math.floor(offsetY + this._bounds.y);
if(srcW > 0 && srcH > 0) {
context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
}
@@ -11729,6 +11750,10 @@ var Phaser;
ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
if (typeof speedX === "undefined") { speedX = 0; }
if (typeof speedY === "undefined") { speedY = 0; }
+ if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
+ return;
+ }
this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
this.regions.push(this.currentRegion);
return this.currentRegion;
@@ -11737,6 +11762,7 @@ var Phaser;
if(this.currentRegion) {
this.currentRegion.scrollSpeed.setTo(x, y);
}
+ return this;
};
ScrollZone.prototype.update = function () {
for(var i = 0; i < this.regions.length; i++) {
diff --git a/Tests/scrollzones/parallax.js b/Tests/scrollzones/parallax.js
index 07862c27..454e7910 100644
--- a/Tests/scrollzones/parallax.js
+++ b/Tests/scrollzones/parallax.js
@@ -7,22 +7,21 @@
myGame.loader.load();
}
function create() {
- // In this example we're creating a whole bunch of ScrollZones working on the same image
var zone = myGame.createScrollZone('starray');
- var y = 10;
- var speed = 6;
- speed -= 0.3;
+ zone.currentRegion.visible = false;
+ var y = 0;
+ var speed = 16;
// The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down)
- for(var z = 0; z < 31; z++) {
+ for(var z = 0; z < 32; z++) {
zone.addRegion(0, y, 640, 10, speed);
- if(z <= 14) {
- speed -= 0.3;
+ if(z <= 15) {
+ speed -= 1;
} else {
- speed += 0.3;
+ speed += 1;
}
- if(z == 14) {
+ if(z == 15) {
y = 240;
- speed += 0.3;
+ speed += 1;
} else {
y += 10;
}
diff --git a/Tests/scrollzones/parallax.ts b/Tests/scrollzones/parallax.ts
index 2b3760f6..3e6b0edc 100644
--- a/Tests/scrollzones/parallax.ts
+++ b/Tests/scrollzones/parallax.ts
@@ -15,32 +15,31 @@
function create() {
- // In this example we're creating a whole bunch of ScrollZones working on the same image
var zone: Phaser.ScrollZone = myGame.createScrollZone('starray');
- var y:number = 10;
- var speed:number = 6;
-
- speed -= 0.3;
+ zone.currentRegion.visible = false;
+
+ var y:number = 0;
+ var speed:number = 16;
// The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down)
- for (var z:number = 0; z < 31; z++)
+ for (var z:number = 0; z < 32; z++)
{
zone.addRegion(0, y, 640, 10, speed);
- if (z <= 14)
+ if (z <= 15)
{
- speed -= 0.3;
+ speed -= 1;
}
else
{
- speed += 0.3;
+ speed += 1;
}
- if (z == 14)
+ if (z == 15)
{
y = 240;
- speed += 0.3;
+ speed += 1;
}
else
{
diff --git a/Tests/scrollzones/region demo.js b/Tests/scrollzones/region demo.js
new file mode 100644
index 00000000..67f73fcd
--- /dev/null
+++ b/Tests/scrollzones/region demo.js
@@ -0,0 +1,22 @@
+///
+///
+(function () {
+ var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
+ function init() {
+ myGame.loader.addImageFile('angelDawn', 'assets/pics/game14_angel_dawn.png');
+ myGame.loader.load();
+ }
+ var scroller;
+ function create() {
+ // This creates our ScrollZone centered in the middle of the stage.
+ scroller = myGame.createScrollZone('angelDawn', myGame.stage.centerX - 320, 100);
+ // By default we won't scroll the full image, but we will create 3 ScrollRegions within it:
+ // This creates a ScrollRegion which can be thought of as a rectangle within the ScrollZone that can be scrolled
+ // independantly - this one scrolls the image of the spacemans head
+ scroller.addRegion(32, 32, 352, 240, 0, 2);
+ // The head in the top right
+ scroller.addRegion(480, 30, 96, 96, 4, 0);
+ // The small piece of text
+ scroller.addRegion(466, 160, 122, 14, 0, -0.5);
+ }
+})();
diff --git a/Tests/scrollzones/region demo.ts b/Tests/scrollzones/region demo.ts
new file mode 100644
index 00000000..a5f3e3d1
--- /dev/null
+++ b/Tests/scrollzones/region demo.ts
@@ -0,0 +1,37 @@
+///
+///
+
+(function () {
+
+ var myGame = new Phaser.Game(this, 'game', 800, 600, init, create);
+
+ function init() {
+
+ myGame.loader.addImageFile('angelDawn', 'assets/pics/game14_angel_dawn.png');
+
+ myGame.loader.load();
+
+ }
+
+ var scroller: Phaser.ScrollZone;
+
+ function create() {
+
+ // This creates our ScrollZone centered in the middle of the stage.
+ scroller = myGame.createScrollZone('angelDawn', myGame.stage.centerX - 320, 100);
+
+ // By default we won't scroll the full image, but we will create 3 ScrollRegions within it:
+
+ // This creates a ScrollRegion which can be thought of as a rectangle within the ScrollZone that can be scrolled
+ // independantly - this one scrolls the image of the spacemans head
+ scroller.addRegion(32, 32, 352, 240, 0, 2);
+
+ // The head in the top right
+ scroller.addRegion(480, 30, 96, 96, 4, 0);
+
+ // The small piece of text
+ scroller.addRegion(466, 160, 122, 14, 0, -0.5);
+
+ }
+
+})();
diff --git a/build/phaser.js b/build/phaser.js
index 150af5fe..e31ef067 100644
--- a/build/phaser.js
+++ b/build/phaser.js
@@ -11581,6 +11581,14 @@ var Phaser;
if (typeof t === "undefined") { t = 0; }
return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t);
};
+ Quad.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return "[{Quad (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + ")}]";
+ };
return Quad;
})();
Phaser.Quad = Quad;
@@ -11603,41 +11611,40 @@ var Phaser;
this._inverseHeight = 0;
this.visible = true;
// Our seamless scrolling quads
- this._A = new Phaser.Quad(0, 0, width, height);
- this._B = new Phaser.Quad();
- this._C = new Phaser.Quad();
- this._D = new Phaser.Quad();
+ this._A = new Phaser.Quad(x, y, width, height);
+ this._B = new Phaser.Quad(x, y, width, height);
+ this._C = new Phaser.Quad(x, y, width, height);
+ this._D = new Phaser.Quad(x, y, width, height);
this._scroll = new Phaser.MicroPoint();
- this._offset = new Phaser.MicroPoint(x, y);
+ this._bounds = new Phaser.Quad(x, y, width, height);
this.scrollSpeed = new Phaser.MicroPoint(speedX, speedY);
- this.bounds = new Phaser.Quad(0, 0, width, height);
}
ScrollRegion.prototype.update = function (delta) {
- this._scroll.x = Math.round(this._scroll.x + (this.scrollSpeed.x));
- this._scroll.y = Math.round(this._scroll.y + (this.scrollSpeed.y));
- if(this._scroll.x > this._offset.x + this.bounds.width) {
- this._scroll.x = this._offset.x;
+ this._scroll.x += this.scrollSpeed.x;
+ this._scroll.y += this.scrollSpeed.y;
+ if(this._scroll.x > this._bounds.right) {
+ this._scroll.x = this._bounds.x;
}
- if(this._scroll.x < this._offset.x) {
- this._scroll.x = this._offset.x + this.bounds.width;
+ if(this._scroll.x < this._bounds.x) {
+ this._scroll.x = this._bounds.right;
}
- if(this._scroll.y > this._offset.y + this.bounds.height) {
- this._scroll.y = this._offset.y;
+ if(this._scroll.y > this._bounds.bottom) {
+ this._scroll.y = this._bounds.y;
}
- if(this._scroll.y < this._offset.y) {
- this._scroll.y = this._offset.y + this.bounds.height;
+ if(this._scroll.y < this._bounds.y) {
+ this._scroll.y = this._bounds.bottom;
}
// Anchor Dimensions
- this._anchorWidth = this.bounds.width - this._scroll.x;
- this._anchorHeight = this.bounds.height - this._scroll.y;
- if(this._anchorWidth > this.bounds.width) {
- this._anchorWidth = this.bounds.width;
+ this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
+ this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
+ if(this._anchorWidth > this._bounds.width) {
+ this._anchorWidth = this._bounds.width;
}
- if(this._anchorHeight > this.bounds.height) {
- this._anchorHeight = this.bounds.height;
+ if(this._anchorHeight > this._bounds.height) {
+ this._anchorHeight = this._bounds.height;
}
- this._inverseWidth = this.bounds.width - this._anchorWidth;
- this._inverseHeight = this.bounds.height - this._anchorHeight;
+ this._inverseWidth = this._bounds.width - this._anchorWidth;
+ this._inverseHeight = this._bounds.height - this._anchorHeight;
// Quad A
this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
// Quad B
@@ -11656,11 +11663,19 @@ var Phaser;
if(this.visible == false) {
return;
}
+ // dx/dy are the world coordinates to render the FULL ScrollZone into.
+ // This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
- };
+ //context.fillStyle = 'rgb(255,255,255)';
+ //context.font = '18px Arial';
+ //context.fillText('QuadA: ' + this._A.toString(), 32, 450);
+ //context.fillText('QuadB: ' + this._B.toString(), 32, 480);
+ //context.fillText('QuadC: ' + this._C.toString(), 32, 510);
+ //context.fillText('QuadD: ' + this._D.toString(), 32, 540);
+ };
ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
offsetX += destX;
offsetY += destY;
@@ -11670,6 +11685,12 @@ var Phaser;
if(srcH > (destY + destH) - offsetY) {
srcH = (destY + destH) - offsetY;
}
+ srcX = Math.floor(srcX);
+ srcY = Math.floor(srcY);
+ srcW = Math.floor(srcW);
+ srcH = Math.floor(srcH);
+ offsetX = Math.floor(offsetX + this._bounds.x);
+ offsetY = Math.floor(offsetY + this._bounds.y);
if(srcW > 0 && srcH > 0) {
context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
}
@@ -11729,6 +11750,10 @@ var Phaser;
ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
if (typeof speedX === "undefined") { speedX = 0; }
if (typeof speedY === "undefined") { speedY = 0; }
+ if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
+ return;
+ }
this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
this.regions.push(this.currentRegion);
return this.currentRegion;
@@ -11737,6 +11762,7 @@ var Phaser;
if(this.currentRegion) {
this.currentRegion.scrollSpeed.setTo(x, y);
}
+ return this;
};
ScrollZone.prototype.update = function () {
for(var i = 0; i < this.regions.length; i++) {