Last active
April 4, 2020 02:32
-
-
Save tickle-monster/629ad7f77018c734bec2f19df6c560f1 to your computer and use it in GitHub Desktop.
Phaser 3 BaseScene (bugged)
This file contains hidden or 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 phaser from 'phaser'; | |
export class BaseScene extends phaser.Scene | |
{ | |
constructor (config) | |
{ | |
super(config); | |
this.user; | |
} | |
init () | |
{ | |
this.user = this.registry.get('user'); | |
} | |
} |
This file contains hidden or 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 phaser from 'phaser'; | |
export class Boot extends phaser.Scene | |
{ | |
constructor () | |
{ | |
super({ key: 'boot' }); | |
} | |
preload () | |
{ | |
} | |
create () | |
{ | |
this.scene.start('preloader'); | |
} | |
} |
This file contains hidden or 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 phaser from 'phaser' | |
import BaseScene from 'base' | |
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 hidden or 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> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script> | |
</head> | |
<body style="margin:0px"> | |
<script type="text/javascript" src="index.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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 Phaser from 'phaser'; | |
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 | |
] | |
}; | |
const game = new Phaser.Game(config); |
This file contains hidden or 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 phaser from 'phaser'; | |
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 hidden or 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