class Example extends Phaser.Scene { constructor () { super(); } preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v385'); this.load.image('einstein', 'assets/pics/ra-einstein.png'); } create () { const image = this.add.image(400, 300, 'einstein'); this.UIText1 = this.add.text(0, 32, '0'); this.UIText2 = this.add.text(0, 64, '0'); this.UIText3 = this.add.text(540, 64, '3'); this.cont1 = this.add.container(); this.cont2 = this.add.container(); this.cont1.add(this.UIText1); this.cont1.add(this.UIText2); this.cont2.add(this.UIText3); this.group = this.add.group(); this.group.add(this.cont1); this.group.add(this.cont2); // Add in a new camera, the same size and position as the main camera const UICam = this.cameras.add(0, 0, 800, 600); // The main camera will not render the children this.cameras.main.ignore(this.group.getChildren()); // The new UI Camera will not render the background image UICam.ignore(image); } update () { this.UIText1.setText("Main camera rotation: " + this.cameras.main.rotation); this.UIText2.setText("Main camera zoom: " + this.cameras.main.zoom); this.UIText3.setText("lol: " + this.cont2.y); //wobble the container this.cont2.y = Math.sin(this.time.now / 100) * 10; this.cameras.main.setZoom(Math.abs(Math.sin(this.cameras.main.rotation)) * 0.5 + 1); this.cameras.main.rotation += 0.01; } } const config = { type: Phaser.AUTO, parent: 'phaser-example', width: 800, height: 600, scene: Example }; const game = new Phaser.Game(config);
Scan to open on your mobile device
class Example extends Phaser.Scene { constructor () { super(); } preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v385'); this.load.image('einstein', 'assets/pics/ra-einstein.png'); } create () { const image = this.add.image(400, 300, 'einstein'); this.UIText1 = this.add.text(0, 32, '0'); this.UIText2 = this.add.text(0, 64, '0'); this.UIText3 = this.add.text(540, 64, '3'); this.cont1 = this.add.container(); this.cont2 = this.add.container(); this.cont1.add(this.UIText1); this.cont1.add(this.UIText2); this.cont2.add(this.UIText3); this.group = this.add.group(); this.group.add(this.cont1); this.group.add(this.cont2); // Add in a new camera, the same size and position as the main camera const UICam = this.cameras.add(0, 0, 800, 600); // The main camera will not render the children this.cameras.main.ignore(this.group.getChildren()); // The new UI Camera will not render the background image UICam.ignore(image); } update () { this.UIText1.setText("Main camera rotation: " + this.cameras.main.rotation); this.UIText2.setText("Main camera zoom: " + this.cameras.main.zoom); this.UIText3.setText("lol: " + this.cont2.y); //wobble the container this.cont2.y = Math.sin(this.time.now / 100) * 10; this.cameras.main.setZoom(Math.abs(Math.sin(this.cameras.main.rotation)) * 0.5 + 1); this.cameras.main.rotation += 0.01; } } const config = { type: Phaser.AUTO, parent: 'phaser-example', width: 800, height: 600, scene: Example }; const game = new Phaser.Game(config);