-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
549fb6a
commit da8f41a
Showing
7 changed files
with
80 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
import Phaser from 'phaser' | ||
|
||
import WebFontFile from '~/utils/WebFontFile' | ||
|
||
export default class HelloWorldScene extends Phaser.Scene { | ||
constructor() { | ||
super('hello-world') | ||
} | ||
|
||
preload() { | ||
this.load.setBaseURL('http://labs.phaser.io') | ||
|
||
this.load.image('sky', 'assets/skies/space3.png') | ||
this.load.image('logo', 'assets/sprites/phaser3-logo.png') | ||
this.load.image('red', 'assets/particles/red.png') | ||
const fonts = new WebFontFile(this.load, 'Roboto Mono') | ||
this.load.addFile(fonts) | ||
} | ||
|
||
create() { | ||
this.add.image(400, 300, 'sky') | ||
|
||
const particles = this.add.particles('red') | ||
|
||
const emitter = particles.createEmitter({ | ||
speed: 100, | ||
scale: { start: 1, end: 0 }, | ||
blendMode: 'ADD', | ||
}) | ||
|
||
const logo = this.physics.add.image(400, 100, 'logo') | ||
|
||
logo.setVelocity(100, 200) | ||
logo.setBounce(1, 1) | ||
logo.setCollideWorldBounds(true) | ||
|
||
emitter.startFollow(logo) | ||
const x = this.scale.width * 0.5 | ||
const y = this.scale.height * 0.5 | ||
|
||
this.add | ||
.text(x, y, 'Bầu trời trong xanh thăm thẳm, không một gợn mây!', { | ||
fontFamily: 'Roboto Mono', | ||
fontSize: '13px', | ||
color: '#fff', | ||
}) | ||
.setOrigin(0.5, 0.5) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
background-color: black; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Phaser from 'phaser' | ||
|
||
import WebFontLoader from 'webfontloader' | ||
|
||
export default class WebFontFile extends Phaser.Loader.File { | ||
private fontNames: string[] = [] | ||
private service: string = '' | ||
|
||
constructor( | ||
loader: Phaser.Loader.LoaderPlugin, | ||
fontNames: string | string[], | ||
service = 'google' | ||
) { | ||
super(loader, { | ||
type: 'webfont', | ||
key: fontNames.toString(), | ||
}) | ||
|
||
this.fontNames = Array.isArray(fontNames) ? fontNames : [fontNames] | ||
this.service = service | ||
} | ||
|
||
load() { | ||
const config = { | ||
active: () => { | ||
this.loader.nextFile(this, true) | ||
}, | ||
} | ||
|
||
switch (this.service) { | ||
case 'google': | ||
config['google'] = { | ||
families: this.fontNames, | ||
} | ||
break | ||
|
||
default: | ||
throw new Error('Unsupported font service') | ||
} | ||
|
||
WebFontLoader.load(config) | ||
} | ||
} |