From dcce5442771b0f60889dc42ebead57a1947b871b Mon Sep 17 00:00:00 2001 From: hades-cntrl <77414369+hades-cntrl@users.noreply.github.com> Date: Wed, 20 Jan 2021 15:25:50 +1300 Subject: [PATCH 1/3] Update rotate around a sprite.js --- .../sprites/rotate around a sprite.js | 74 ++++++++++++------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/public/src/game objects/sprites/rotate around a sprite.js b/public/src/game objects/sprites/rotate around a sprite.js index 9280230ee..eb9a68a58 100644 --- a/public/src/game objects/sprites/rotate around a sprite.js +++ b/public/src/game objects/sprites/rotate around a sprite.js @@ -1,39 +1,57 @@ -var config = { - type: Phaser.AUTO, - parent: 'phaser-example', - width: 800, - height: 600, - scene: { - preload: preload, - create: create, - update: update +class Example extends Phaser.Scene +{ + constructor () + { + super(); } -}; -var ball1; -var ball2; -var ball3; + preload () + { + this.load.image('ballRed', 'assets/demoscene/ball.png'); + this.load.image('ballBlue', 'assets/demoscene/blue_ball.png'); + this.load.image('ballSmall', 'assets/demoscene/ball-tlb.png'); + } -var angle1 = 0; -var distance1 = 200; + create () + { + ball1 = this.add.sprite(400, 300, 'ballRed'); + ball2 = this.add.sprite(400, 300, 'ballBlue'); + ball3 = this.add.sprite(400, 300, 'ballSmall'); + } -var angle2 = 0; -var distance2 = 80; + update() + { + ball2.setPosition(400, 300); + ball3.setPosition(400, 300); -var game = new Phaser.Game(config); + Phaser.Math.RotateAroundDistance(ball2, ball1.x, ball1.y, angle1, distance1); + Phaser.Math.RotateAroundDistance(ball3, ball2.x, ball2.y, angle2, distance2); -function preload () -{ - this.load.image('ballRed', 'assets/demoscene/ball.png'); - this.load.image('ballBlue', 'assets/demoscene/blue_ball.png'); - this.load.image('ballSmall', 'assets/demoscene/ball-tlb.png'); + angle1 = Phaser.Math.Angle.Wrap(angle1 + 0.02); + angle2 = Phaser.Math.Angle.Wrap(angle2 + 0.03); + } } -function create () -{ - ball1 = this.add.sprite(400, 300, 'ballRed'); - ball2 = this.add.sprite(400, 300, 'ballBlue'); - ball3 = this.add.sprite(400, 300, 'ballSmall'); +let ball1; +let ball2; +let ball3; + +let angle1 = 0; +let distance1 = 200; + +let angle2 = 0; +let distance2 = 80; + +const config = { + type: Phaser.AUTO, + parent: 'phaser-example', + width: 800, + height: 600, + scene: [ Example] +}; + +const game = new Phaser.Game(config); + } function update () From 26c510424aa996890bf29242d7f73978ed630b74 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 21 Jan 2021 15:54:57 +1300 Subject: [PATCH 2/3] changed to es6 --- .../sprites/rotate around a sprite.js | 51 ++++++------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/public/src/game objects/sprites/rotate around a sprite.js b/public/src/game objects/sprites/rotate around a sprite.js index eb9a68a58..c65f68526 100644 --- a/public/src/game objects/sprites/rotate around a sprite.js +++ b/public/src/game objects/sprites/rotate around a sprite.js @@ -3,8 +3,14 @@ class Example extends Phaser.Scene constructor () { super(); + this.ball1 = undefined; + this.ball2 = undefined; + this.ball3 = undefined; + this.angle1 = 0; + this.distance1 = 200; + this.angle2 = 0; + this.distance2 = 80; } - preload () { this.load.image('ballRed', 'assets/demoscene/ball.png'); @@ -14,34 +20,24 @@ class Example extends Phaser.Scene create () { - ball1 = this.add.sprite(400, 300, 'ballRed'); - ball2 = this.add.sprite(400, 300, 'ballBlue'); - ball3 = this.add.sprite(400, 300, 'ballSmall'); + this.ball1 = this.add.sprite(400, 300, 'ballRed'); + this.ball2 = this.add.sprite(400, 300, 'ballBlue'); + this.ball3 = this.add.sprite(400, 300, 'ballSmall'); } update() { - ball2.setPosition(400, 300); - ball3.setPosition(400, 300); + this.ball2.setPosition(400, 300); + this.ball3.setPosition(400, 300); - Phaser.Math.RotateAroundDistance(ball2, ball1.x, ball1.y, angle1, distance1); - Phaser.Math.RotateAroundDistance(ball3, ball2.x, ball2.y, angle2, distance2); + Phaser.Math.RotateAroundDistance(this.ball2, this.ball1.x, this.ball1.y, this.angle1, this.distance1); + Phaser.Math.RotateAroundDistance(this.ball3, this.ball2.x, this.ball2.y, this.angle2, this.distance2); - angle1 = Phaser.Math.Angle.Wrap(angle1 + 0.02); - angle2 = Phaser.Math.Angle.Wrap(angle2 + 0.03); + this.angle1 = Phaser.Math.Angle.Wrap(this.angle1 + 0.02); + this.angle2 = Phaser.Math.Angle.Wrap(this.angle2 + 0.03); } } -let ball1; -let ball2; -let ball3; - -let angle1 = 0; -let distance1 = 200; - -let angle2 = 0; -let distance2 = 80; - const config = { type: Phaser.AUTO, parent: 'phaser-example', @@ -51,18 +47,3 @@ const config = { }; const game = new Phaser.Game(config); - -} - -function update () -{ - // Reset the position so the rotation gets the correct _new_ position - ball2.setPosition(400, 300); - ball3.setPosition(400, 300); - - Phaser.Math.RotateAroundDistance(ball2, ball1.x, ball1.y, angle1, distance1); - Phaser.Math.RotateAroundDistance(ball3, ball2.x, ball2.y, angle2, distance2); - - angle1 = Phaser.Math.Angle.Wrap(angle1 + 0.02); - angle2 = Phaser.Math.Angle.Wrap(angle2 + 0.03); -} From 755b65fae895307c201a8b3deeba13434f5df4cb Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 22 Jan 2021 09:35:03 +1300 Subject: [PATCH 3/3] consistent indentation --- .../sprites/rotate around a sprite.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/public/src/game objects/sprites/rotate around a sprite.js b/public/src/game objects/sprites/rotate around a sprite.js index c65f68526..422a2e0c9 100644 --- a/public/src/game objects/sprites/rotate around a sprite.js +++ b/public/src/game objects/sprites/rotate around a sprite.js @@ -13,37 +13,37 @@ class Example extends Phaser.Scene } preload () { - this.load.image('ballRed', 'assets/demoscene/ball.png'); - this.load.image('ballBlue', 'assets/demoscene/blue_ball.png'); - this.load.image('ballSmall', 'assets/demoscene/ball-tlb.png'); + this.load.image('ballRed', 'assets/demoscene/ball.png'); + this.load.image('ballBlue', 'assets/demoscene/blue_ball.png'); + this.load.image('ballSmall', 'assets/demoscene/ball-tlb.png'); } create () { - this.ball1 = this.add.sprite(400, 300, 'ballRed'); - this.ball2 = this.add.sprite(400, 300, 'ballBlue'); - this.ball3 = this.add.sprite(400, 300, 'ballSmall'); + this.ball1 = this.add.sprite(400, 300, 'ballRed'); + this.ball2 = this.add.sprite(400, 300, 'ballBlue'); + this.ball3 = this.add.sprite(400, 300, 'ballSmall'); } update() { - this.ball2.setPosition(400, 300); - this.ball3.setPosition(400, 300); + this.ball2.setPosition(400, 300); + this.ball3.setPosition(400, 300); - Phaser.Math.RotateAroundDistance(this.ball2, this.ball1.x, this.ball1.y, this.angle1, this.distance1); - Phaser.Math.RotateAroundDistance(this.ball3, this.ball2.x, this.ball2.y, this.angle2, this.distance2); + Phaser.Math.RotateAroundDistance(this.ball2, this.ball1.x, this.ball1.y, this.angle1, this.distance1); + Phaser.Math.RotateAroundDistance(this.ball3, this.ball2.x, this.ball2.y, this.angle2, this.distance2); - this.angle1 = Phaser.Math.Angle.Wrap(this.angle1 + 0.02); - this.angle2 = Phaser.Math.Angle.Wrap(this.angle2 + 0.03); + this.angle1 = Phaser.Math.Angle.Wrap(this.angle1 + 0.02); + this.angle2 = Phaser.Math.Angle.Wrap(this.angle2 + 0.03); } } const config = { - type: Phaser.AUTO, - parent: 'phaser-example', - width: 800, - height: 600, - scene: [ Example] + type: Phaser.AUTO, + parent: 'phaser-example', + width: 800, + height: 600, + scene: [ Example] }; const game = new Phaser.Game(config);