@@ -11581,6 +11581,14 @@ var Phaser;
1158111581 if (typeof t === "undefined") { t = 0; }
1158211582 return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t);
1158311583 };
11584+ Quad.prototype.toString = /**
11585+ * Returns a string representation of this object.
11586+ * @method toString
11587+ * @return {string} a string representation of the object.
11588+ **/
11589+ function () {
11590+ return "[{Quad (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + ")}]";
11591+ };
1158411592 return Quad;
1158511593 })();
1158611594 Phaser.Quad = Quad;
@@ -11603,41 +11611,40 @@ var Phaser;
1160311611 this._inverseHeight = 0;
1160411612 this.visible = true;
1160511613 // Our seamless scrolling quads
11606- this . _A = new Phaser . Quad ( 0 , 0 , width , height ) ;
11607- this . _B = new Phaser . Quad ( ) ;
11608- this . _C = new Phaser . Quad ( ) ;
11609- this . _D = new Phaser . Quad ( ) ;
11614+ this._A = new Phaser.Quad(x, y , width, height);
11615+ this._B = new Phaser.Quad(x, y, width, height );
11616+ this._C = new Phaser.Quad(x, y, width, height );
11617+ this._D = new Phaser.Quad(x, y, width, height );
1161011618 this._scroll = new Phaser.MicroPoint();
11611- this . _offset = new Phaser . MicroPoint ( x , y ) ;
11619+ this._bounds = new Phaser.Quad (x, y, width, height );
1161211620 this.scrollSpeed = new Phaser.MicroPoint(speedX, speedY);
11613- this . bounds = new Phaser . Quad ( 0 , 0 , width , height ) ;
1161411621 }
1161511622 ScrollRegion.prototype.update = function (delta) {
11616- this . _scroll . x = Math . round ( this . _scroll . x + ( this . scrollSpeed . x ) ) ;
11617- this . _scroll . y = Math . round ( this . _scroll . y + ( this . scrollSpeed . y ) ) ;
11618- if ( this . _scroll . x > this . _offset . x + this . bounds . width ) {
11619- this . _scroll . x = this . _offset . x ;
11623+ this._scroll.x += this.scrollSpeed.x;
11624+ this._scroll.y += this.scrollSpeed.y;
11625+ if(this._scroll.x > this._bounds.right ) {
11626+ this._scroll.x = this._bounds .x;
1162011627 }
11621- if ( this . _scroll . x < this . _offset . x ) {
11622- this . _scroll . x = this . _offset . x + this . bounds . width ;
11628+ if(this._scroll.x < this._bounds .x) {
11629+ this._scroll.x = this._bounds.right ;
1162311630 }
11624- if ( this . _scroll . y > this . _offset . y + this . bounds . height ) {
11625- this . _scroll . y = this . _offset . y ;
11631+ if(this._scroll.y > this._bounds.bottom ) {
11632+ this._scroll.y = this._bounds .y;
1162611633 }
11627- if ( this . _scroll . y < this . _offset . y ) {
11628- this . _scroll . y = this . _offset . y + this . bounds . height ;
11634+ if(this._scroll.y < this._bounds .y) {
11635+ this._scroll.y = this._bounds.bottom ;
1162911636 }
1163011637 // Anchor Dimensions
11631- this . _anchorWidth = this . bounds . width - this . _scroll . x ;
11632- this . _anchorHeight = this . bounds . height - this . _scroll . y ;
11633- if ( this . _anchorWidth > this . bounds . width ) {
11634- this . _anchorWidth = this . bounds . width ;
11638+ this._anchorWidth = ( this._bounds .width - this._scroll.x) + this._bounds .x;
11639+ this._anchorHeight = ( this._bounds .height - this._scroll.y) + this._bounds .y;
11640+ if(this._anchorWidth > this._bounds .width) {
11641+ this._anchorWidth = this._bounds .width;
1163511642 }
11636- if ( this . _anchorHeight > this . bounds . height ) {
11637- this . _anchorHeight = this . bounds . height ;
11643+ if(this._anchorHeight > this._bounds .height) {
11644+ this._anchorHeight = this._bounds .height;
1163811645 }
11639- this . _inverseWidth = this . bounds . width - this . _anchorWidth ;
11640- this . _inverseHeight = this . bounds . height - this . _anchorHeight ;
11646+ this._inverseWidth = this._bounds .width - this._anchorWidth;
11647+ this._inverseHeight = this._bounds .height - this._anchorHeight;
1164111648 // Quad A
1164211649 this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
1164311650 // Quad B
@@ -11656,11 +11663,19 @@ var Phaser;
1165611663 if(this.visible == false) {
1165711664 return;
1165811665 }
11666+ // dx/dy are the world coordinates to render the FULL ScrollZone into.
11667+ // This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
1165911668 this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
1166011669 this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
1166111670 this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
1166211671 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);
11663- } ;
11672+ //context.fillStyle = 'rgb(255,255,255)';
11673+ //context.font = '18px Arial';
11674+ //context.fillText('QuadA: ' + this._A.toString(), 32, 450);
11675+ //context.fillText('QuadB: ' + this._B.toString(), 32, 480);
11676+ //context.fillText('QuadC: ' + this._C.toString(), 32, 510);
11677+ //context.fillText('QuadD: ' + this._D.toString(), 32, 540);
11678+ };
1166411679 ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
1166511680 offsetX += destX;
1166611681 offsetY += destY;
@@ -11670,6 +11685,12 @@ var Phaser;
1167011685 if(srcH > (destY + destH) - offsetY) {
1167111686 srcH = (destY + destH) - offsetY;
1167211687 }
11688+ srcX = Math.floor(srcX);
11689+ srcY = Math.floor(srcY);
11690+ srcW = Math.floor(srcW);
11691+ srcH = Math.floor(srcH);
11692+ offsetX = Math.floor(offsetX + this._bounds.x);
11693+ offsetY = Math.floor(offsetY + this._bounds.y);
1167311694 if(srcW > 0 && srcH > 0) {
1167411695 context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
1167511696 }
@@ -11729,6 +11750,10 @@ var Phaser;
1172911750 ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
1173011751 if (typeof speedX === "undefined") { speedX = 0; }
1173111752 if (typeof speedY === "undefined") { speedY = 0; }
11753+ if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
11754+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
11755+ return;
11756+ }
1173211757 this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
1173311758 this.regions.push(this.currentRegion);
1173411759 return this.currentRegion;
@@ -11737,6 +11762,7 @@ var Phaser;
1173711762 if(this.currentRegion) {
1173811763 this.currentRegion.scrollSpeed.setTo(x, y);
1173911764 }
11765+ return this;
1174011766 };
1174111767 ScrollZone.prototype.update = function () {
1174211768 for(var i = 0; i < this.regions.length; i++) {
0 commit comments