AhrenHart Posted January 20, 2021 Share Posted January 20, 2021 here is my code i know its not efficient but it i'm trying to have music stay the same between the scenes and have the option to mute the audio and work throughout the scenes. class TitleScene extends Phaser.Scene{ constructor() { super({key: 'TitleScene', active: true }); } preload (){ this.load.image('background_image', 'assets/images/MainMenuImg.png'); this.load.image('Play', 'assets/images/Play.png'); this.load.image('Options', 'assets/images/Options.png'); } create (){ let background = this.add.sprite(-100,0, 'background_image'); background.setOrigin(0,0); background.scale = 0.7; //let playText = this.add.text(225,125, 'Play') //playText.addcolor ('#ffff00') var playButton = this.add.image(250,125,'Play').setDepth(1); playButton.setInteractive(); playButton.on('pointerup', function () { this.scene.add('test',Test,true) }, this); var OptionsButton = this.add.image(250,180,'Options').setDepth(1); OptionsButton.scale = 1.5; OptionsButton.setInteractive(); OptionsButton.on('pointerup', function () { this.scene.add('options',Options,true) }, this); } } class Test extends Phaser.Scene{ constructor() { super({key: 'test', active: true }); } preload (){ this.load.image('TestImg', 'assets/images/Cemetery.png'); } create (){ let TestImg = this.add.sprite(0,0, 'TestImg'); TestImg.setOrigin(0,0); //TestImg.scale = 0; } } class Options extends Phaser.Scene{ constructor() { super({key: 'options', active: true }); } preload (){ this.load.image('OptionsMenu', 'assets/images/OptionsMenuScreen.png'); this.load.image('XBut', 'assets/images/X.png'); } create (){ let OptionsMenu = this.add.sprite(0,0, 'OptionsMenu'); OptionsMenu.setOrigin(0,0); var XButton = this.add.image(25,25,'XBut').setDepth(1); XButton.scale = 2; XButton.setInteractive(); XButton.on('pointerup', function () { this.scene.start('TitleScene',TitleScene,true) }, this); } } let config = { type: Phaser.AUTO, // Which renderer to use width: 512, // Canvas width in pixels height: 512, // Canvas height in pixels parent: "game-container", // ID of the DOM element to add the canvas to scene:[TitleScene] }; let game = new Phaser.Game(config); Link to comment Share on other sites More sharing options...
Recommended Posts