Build games as easily as you play them — join the Phaser Beam waitlist for Early Access.
var SceneA = new Phaser.Class({ Extends: Phaser.Scene, initialize: function SceneA () { Phaser.Scene.call(this, { key: 'sceneA' }); }, preload: function () { this.load.image('face', 'assets/pics/bw-face.png'); }, create: function () { this.add.sprite(400, 300, 'face').setAlpha(0.2); this.input.once('pointerdown', function () { console.log('From SceneA to SceneB'); this.scene.start('sceneB'); }, this); } }); var SceneB = new Phaser.Class({ Extends: Phaser.Scene, initialize: function SceneB () { Phaser.Scene.call(this, { key: 'sceneB' }); }, preload: function () { this.load.image('arrow', 'assets/sprites/longarrow.png'); }, create: function () { this.arrow = this.add.sprite(400, 300, 'arrow').setOrigin(0, 0.5); this.input.once('pointerdown', function (event) { console.log('From SceneB to SceneC'); this.scene.start('sceneC'); }, this); }, update: function (time, delta) { this.arrow.rotation += 0.01; } }); var SceneC = new Phaser.Class({ Extends: Phaser.Scene, initialize: function SceneC () { Phaser.Scene.call(this, { key: 'sceneC' }); }, preload: function () { this.load.image('mech', 'assets/pics/titan-mech.png'); }, create: function () { this.add.sprite(Phaser.Math.Between(0, 800), 300, 'mech'); this.input.once('pointerdown', function (event) { console.log('From SceneC to SceneA'); this.scene.start('sceneA'); }, this); } }); var config = { type: Phaser.AUTO, width: 800, height: 600, backgroundColor: '#000000', parent: 'phaser-example', scene: [ SceneA, SceneB, SceneC ] }; var game = new Phaser.Game(config);
var SceneA = new Phaser.Class({
Extends: Phaser.Scene,
initialize:
function SceneA ()
{
Phaser.Scene.call(this, { key: 'sceneA' });
},
preload: function ()
{
this.load.image('face', 'assets/pics/bw-face.png');
},
create: function ()
{
this.add.sprite(400, 300, 'face').setAlpha(0.2);
this.input.once('pointerdown', function () {
console.log('From SceneA to SceneB');
this.scene.start('sceneB');
}, this);
}
});
var SceneB = new Phaser.Class({
Extends: Phaser.Scene,
initialize:
function SceneB ()
{
Phaser.Scene.call(this, { key: 'sceneB' });
},
preload: function ()
{
this.load.image('arrow', 'assets/sprites/longarrow.png');
},
create: function ()
{
this.arrow = this.add.sprite(400, 300, 'arrow').setOrigin(0, 0.5);
this.input.once('pointerdown', function (event) {
console.log('From SceneB to SceneC');
this.scene.start('sceneC');
}, this);
},
update: function (time, delta)
{
this.arrow.rotation += 0.01;
}
});
var SceneC = new Phaser.Class({
Extends: Phaser.Scene,
initialize:
function SceneC ()
{
Phaser.Scene.call(this, { key: 'sceneC' });
},
preload: function ()
{
this.load.image('mech', 'assets/pics/titan-mech.png');
},
create: function ()
{
this.add.sprite(Phaser.Math.Between(0, 800), 300, 'mech');
this.input.once('pointerdown', function (event) {
console.log('From SceneC to SceneA');
this.scene.start('sceneA');
}, this);
}
});
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#000000',
parent: 'phaser-example',
scene: [ SceneA, SceneB, SceneC ]
};
var game = new Phaser.Game(config);