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..422a2e0c9 100644 --- a/public/src/game objects/sprites/rotate around a sprite.js +++ b/public/src/game objects/sprites/rotate around a sprite.js @@ -1,50 +1,49 @@ -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(); + 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'); + this.load.image('ballBlue', 'assets/demoscene/blue_ball.png'); + this.load.image('ballSmall', 'assets/demoscene/ball-tlb.png'); } -}; - -var ball1; -var ball2; -var ball3; - -var angle1 = 0; -var distance1 = 200; -var angle2 = 0; -var distance2 = 80; + 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'); + } -var game = new Phaser.Game(config); + update() + { + this.ball2.setPosition(400, 300); + this.ball3.setPosition(400, 300); -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'); -} + 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); -function create () -{ - ball1 = this.add.sprite(400, 300, 'ballRed'); - ball2 = this.add.sprite(400, 300, 'ballBlue'); - ball3 = this.add.sprite(400, 300, 'ballSmall'); + this.angle1 = Phaser.Math.Angle.Wrap(this.angle1 + 0.02); + this.angle2 = Phaser.Math.Angle.Wrap(this.angle2 + 0.03); + } } -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); +const config = { + type: Phaser.AUTO, + parent: 'phaser-example', + width: 800, + height: 600, + scene: [ Example] +}; - angle1 = Phaser.Math.Angle.Wrap(angle1 + 0.02); - angle2 = Phaser.Math.Angle.Wrap(angle2 + 0.03); -} +const game = new Phaser.Game(config);