From 383f14cb3f539a18af8f81d7859803481872c994 Mon Sep 17 00:00:00 2001 From: Robert Bedard Date: Fri, 29 Jul 2016 15:08:29 -0400 Subject: [PATCH 1/4] Weapon.Fire now tracks offset rotation --- src/plugins/weapon/WeaponPlugin.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/plugins/weapon/WeaponPlugin.js b/src/plugins/weapon/WeaponPlugin.js index 9bf95622f6..717f815b81 100644 --- a/src/plugins/weapon/WeaponPlugin.js +++ b/src/plugins/weapon/WeaponPlugin.js @@ -730,14 +730,32 @@ Phaser.Weapon.prototype.fire = function (from, x, y) { } else if (this.trackedSprite) { - if (this.fireFrom.width > 1) + if (this.trackRotation) { - this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); + + if (this.fireFrom.width > 1) + { + this.fireFrom.centerOn(rotatedPoint.x, rotatedPoint.y); + } + else + { + this.fireFrom.x = rotatedPoint.x; + this.fireFrom.y = rotatedPoint.y; + } } else { - this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x; - this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y; + if (this.fireFrom.width > 1) + { + this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + } + else + { + this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x; + this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y; + } } if (this.bulletInheritSpriteSpeed) From 6d7b84b10e53229213b6f745292c8c36afb3653c Mon Sep 17 00:00:00 2001 From: bobonthenet Date: Fri, 29 Jul 2016 19:24:49 -0400 Subject: [PATCH 2/4] Fixed jshint errors --- src/plugins/weapon/WeaponPlugin.js | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/plugins/weapon/WeaponPlugin.js b/src/plugins/weapon/WeaponPlugin.js index 717f815b81..caf7495a37 100644 --- a/src/plugins/weapon/WeaponPlugin.js +++ b/src/plugins/weapon/WeaponPlugin.js @@ -730,38 +730,38 @@ Phaser.Weapon.prototype.fire = function (from, x, y) { } else if (this.trackedSprite) { - if (this.trackRotation) + if (this.trackRotation) + { + var rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); + + if (this.fireFrom.width > 1) { - rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); - rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); - - if (this.fireFrom.width > 1) - { - this.fireFrom.centerOn(rotatedPoint.x, rotatedPoint.y); - } - else - { - this.fireFrom.x = rotatedPoint.x; - this.fireFrom.y = rotatedPoint.y; - } + this.fireFrom.centerOn(rotatedPoint.x, rotatedPoint.y); } else { - if (this.fireFrom.width > 1) - { - this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); - } - else - { - this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x; - this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y; - } + this.fireFrom.x = rotatedPoint.x; + this.fireFrom.y = rotatedPoint.y; } - - if (this.bulletInheritSpriteSpeed) + } + else + { + if (this.fireFrom.width > 1) { - speed += this.trackedSprite.body.speed; + this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); } + else + { + this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x; + this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y; + } + } + + if (this.bulletInheritSpriteSpeed) + { + speed += this.trackedSprite.body.speed; + } } else if (this.trackedPointer) { From 6df44bd21a3f7dde984a4fb77aacf54b336c4b4b Mon Sep 17 00:00:00 2001 From: bobonthenet Date: Fri, 29 Jul 2016 19:38:37 -0400 Subject: [PATCH 3/4] Apparently I didn't fix them the first time --- src/plugins/weapon/WeaponPlugin.js | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/plugins/weapon/WeaponPlugin.js b/src/plugins/weapon/WeaponPlugin.js index caf7495a37..892626dd7b 100644 --- a/src/plugins/weapon/WeaponPlugin.js +++ b/src/plugins/weapon/WeaponPlugin.js @@ -730,38 +730,38 @@ Phaser.Weapon.prototype.fire = function (from, x, y) { } else if (this.trackedSprite) { - if (this.trackRotation) - { - var rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); - rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); - - if (this.fireFrom.width > 1) + if (this.trackRotation) { - this.fireFrom.centerOn(rotatedPoint.x, rotatedPoint.y); + var rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); + + if (this.fireFrom.width > 1) + { + this.fireFrom.centerOn(rotatedPoint.x, rotatedPoint.y); + } + else + { + this.fireFrom.x = rotatedPoint.x; + this.fireFrom.y = rotatedPoint.y; + } } else { - this.fireFrom.x = rotatedPoint.x; - this.fireFrom.y = rotatedPoint.y; - } - } - else - { - if (this.fireFrom.width > 1) - { - this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + if (this.fireFrom.width > 1) + { + this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + } + else + { + this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x; + this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y; + } } - else + + if (this.bulletInheritSpriteSpeed) { - this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x; - this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y; + speed += this.trackedSprite.body.speed; } - } - - if (this.bulletInheritSpriteSpeed) - { - speed += this.trackedSprite.body.speed; - } } else if (this.trackedPointer) { From 7da56045001ca943a3ec87b65e24c0562de959be Mon Sep 17 00:00:00 2001 From: bobonthenet Date: Mon, 22 Aug 2016 21:36:49 -0400 Subject: [PATCH 4/4] Use this.rotatedPoint instead of a new object --- src/plugins/weapon/WeaponPlugin.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/plugins/weapon/WeaponPlugin.js b/src/plugins/weapon/WeaponPlugin.js index 892626dd7b..fed64b4bb7 100644 --- a/src/plugins/weapon/WeaponPlugin.js +++ b/src/plugins/weapon/WeaponPlugin.js @@ -732,17 +732,23 @@ Phaser.Weapon.prototype.fire = function (from, x, y) { { if (this.trackRotation) { - var rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); - rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); + if(!this.rotatedPoint) + { + this.rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y); + } else { + this.rotatedPoint.x = this.trackedSprite.world.x + this.trackOffset.x; + this.rotatedPoint.y = this.trackedSprite.world.y + this.trackOffset.y; + } + this.rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation); if (this.fireFrom.width > 1) { - this.fireFrom.centerOn(rotatedPoint.x, rotatedPoint.y); + this.fireFrom.centerOn(this.rotatedPoint.x, this.rotatedPoint.y); } else { - this.fireFrom.x = rotatedPoint.x; - this.fireFrom.y = rotatedPoint.y; + this.fireFrom.x = this.rotatedPoint.x; + this.fireFrom.y = this.rotatedPoint.y; } } else