Skip to content

Commit dfbdd59

Browse files
authored
Merge pull request phaserjs#2672 from bobonthenet/master
Weapon.Fire now tracks offset rotation
2 parents d8cb40a + 7da5604 commit dfbdd59

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

src/plugins/weapon/WeaponPlugin.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,38 @@ Phaser.Weapon.prototype.fire = function (from, x, y) {
730730
}
731731
else if (this.trackedSprite)
732732
{
733-
if (this.fireFrom.width > 1)
733+
if (this.trackRotation)
734734
{
735-
this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y);
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+
744+
if (this.fireFrom.width > 1)
745+
{
746+
this.fireFrom.centerOn(this.rotatedPoint.x, this.rotatedPoint.y);
747+
}
748+
else
749+
{
750+
this.fireFrom.x = this.rotatedPoint.x;
751+
this.fireFrom.y = this.rotatedPoint.y;
752+
}
736753
}
737754
else
738755
{
739-
this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x;
740-
this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y;
756+
if (this.fireFrom.width > 1)
757+
{
758+
this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y);
759+
}
760+
else
761+
{
762+
this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x;
763+
this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y;
764+
}
741765
}
742766

743767
if (this.bulletInheritSpriteSpeed)

0 commit comments

Comments
 (0)