Skip to content

Commit cbbb2cd

Browse files
committed
Created _rotatedPoint in the constructor, and tidied up code formatting to match the rest of Phaser phaserjs#2672
1 parent 2409499 commit cbbb2cd

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/plugins/weapon/WeaponPlugin.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ Phaser.Weapon = function (game, parent) {
367367
*/
368368
this._nextFire = 0;
369369

370+
/**
371+
* Internal firing rotation tracking point.
372+
*
373+
* @type {Phaser.Point}
374+
* @private
375+
*/
376+
this._rotatedPoint = new Phaser.Point();
377+
370378
};
371379

372380
Phaser.Weapon.prototype = Object.create(Phaser.Plugin.prototype);
@@ -732,23 +740,17 @@ Phaser.Weapon.prototype.fire = function (from, x, y) {
732740
{
733741
if (this.trackRotation)
734742
{
735-
if(!this.rotatedPoint)
736-
{
737-
this.rotatedPoint = new Phaser.Point(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y);
738-
} else {
739-
this.rotatedPoint.x = this.trackedSprite.world.x + this.trackOffset.x;
740-
this.rotatedPoint.y = this.trackedSprite.world.y + this.trackOffset.y;
741-
}
742-
this.rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation);
743+
this._rotatedPoint.set(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y);
744+
this._rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation);
743745

744746
if (this.fireFrom.width > 1)
745747
{
746-
this.fireFrom.centerOn(this.rotatedPoint.x, this.rotatedPoint.y);
748+
this.fireFrom.centerOn(this._rotatedPoint.x, this._rotatedPoint.y);
747749
}
748750
else
749751
{
750-
this.fireFrom.x = this.rotatedPoint.x;
751-
this.fireFrom.y = this.rotatedPoint.y;
752+
this.fireFrom.x = this._rotatedPoint.x;
753+
this.fireFrom.y = this._rotatedPoint.y;
752754
}
753755
}
754756
else

0 commit comments

Comments
 (0)