-
-
Save samme/e279815537b171d05442e89c8acda8ab to your computer and use it in GitHub Desktop.
Phaser 3 BaseScene
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class BaseScene extends Phaser.Scene | |
{ | |
constructor(config) | |
{ | |
super(config); | |
} | |
init() | |
{ | |
this.user = this.registry.get('user'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Boot extends Phaser.Scene | |
{ | |
constructor() | |
{ | |
super({ key: 'boot' }); | |
} | |
preload() {} | |
create() | |
{ | |
this.scene.start('preloader'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BaseScene } from './base.js'; | |
export class Home extends BaseScene | |
{ | |
constructor() | |
{ | |
super({ | |
key: 'home' | |
}); | |
} | |
init (data) | |
{ | |
super.init(); | |
} | |
create () | |
{ | |
this.add.text(20, 15, 'BaseScene Test', { fontFamily: 'Courier', fontSize: 30, color: 'white', align: 'left' }).setOrigin(0); | |
this.add.text(20, 65, this.user.username, { fontFamily: 'Courier', fontSize: 30, color: 'white', align: 'left' }).setOrigin(0); | |
} | |
update () {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>BaseScene Test</title> | |
</head> | |
<body style="margin:0px"> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script> | |
<script type="module" src="index.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Boot } from './boot'; | |
import { Preloader } from './preloader'; | |
import { Home } from './home'; | |
const config = { | |
scale: { | |
mode: Phaser.Scale.FIT, | |
parent: 'phaser-example', | |
autoCenter: Phaser.Scale.CENTER_BOTH, | |
width: 1136, | |
height: 640 | |
}, | |
scene: [ | |
Boot, | |
Preloader, | |
Home | |
], | |
callbacks: { | |
postBoot: function (game) { | |
game.scene.dump(); | |
} | |
} | |
}; | |
const game = new Phaser.Game(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Preloader extends Phaser.Scene | |
{ | |
constructor() | |
{ | |
super({ | |
key: 'preloader' | |
}); | |
} | |
preload() | |
{ | |
this.load.json('userData', 'user.json'); | |
} | |
create() | |
{ | |
var user = this.cache.json.get('userData'); | |
this.registry.set('user', user); | |
this.scene.start('home'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"id":1,"username":"batman"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment