I’m using half a dozen scenes with this pattern and things seem to work. Only one scene is more complicated than just a background image scene. Working with Code Pen made it clear that I need to pay very close attention to placement of brackets, parentheses etc. and letter case. However, I’m still struggling to replace one of these working scenes with an external scene file version.
var OptionsScene = new Phaser.Class({
Extends: Phaser.Scene,
initialize:
function OptionsScene ()
{
Phaser.Scene.call(this, { key: ‘optionsScene’, active: false });
},
preload ()
{
this.load.image(‘vavilov’, ‘https://cdn.glitch.com/dad6f70b-d7f8-4b6b-812a-427943582a20%2F800px-Maize_diversity_in_Vavilovs_office_(3421259242).jpg?v=1574372062843’);
},
create ()
{
// this.optionsScene = this.add.image(400, 300, ‘optionsscene’);
this.optionsScene = this.add.sprite(400, 300, ‘vavilov’).setOrigin(0.5, 0.5);
this.add.text(20, 20, ‘Options Scene’, { fontFamily: ‘Arial’, fontSize: 64, color: ‘#ffff00’ });
this.add.text(100, 200, ‘toggle music\ntoggle sound\nreturn to menu’, { fontFamily: ‘Arial’, fontSize: 64, color: ‘#ffffff’ });
this.input.once(‘pointerdown’, function () { // just for temporary viewing of scenes
console.log(‘From Options Scene to GameScene’);// actually will be coded to return to menu
this.scene.start(‘gameScene’); // view the intro game scene that will run from Menu -> Start Game
}, this);
}
});
let config = {
type: Phaser.AUTO,
backgroundColor: ‘#00ff00’, // variation: backgroundColor: 0xffff00,
scale: {
mode: Phaser.Scale.FIT,
parent: ‘gameArea’, // div tag id
width: 800,
height: 600
},
pixelArt: true,
zoom: 1,
physics: {
default: ‘arcade’
},
scene: [ BootScene, MenuScene, OptionsScene, GameScene, FSMScene, GameOverScene, CreditsScene ] // adding SceneMain (the external scene file) to the list gives a SceneMain not defined error
};
var game = new Phaser.Game(config);