-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from devshareacademy/phaser-custom-fonts-native
Phaser custom fonts native
- Loading branch information
Showing
11 changed files
with
118,571 additions
and
0 deletions.
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"recommendations": ["esbenp.prettier-vscode", "ritwickdey.LiveServer"] | ||
} |
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,11 @@ | ||
{ | ||
"eslint.format.enable": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"prettier.singleQuote": true, | ||
"prettier.semi": true, | ||
"editor.formatOnSave": true, | ||
"cSpell.words": ["Kenney"] | ||
} |
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,17 @@ | ||
# Phaser 3 - Custom Fonts With Native Phaser | ||
|
||
![demo](docs/example.png) | ||
|
||
A quick demo of how you can easily use custom fonts in Phaser 3 by using the new `FontFile` Loader! This new loader is available in Phaser `3.87.0`, and it has support for `TTF/OTF` out of the box, so you no longer need to use a 3rd party font loader. | ||
|
||
For a detailed walkthrough, checkout my video on YouTube here: | ||
|
||
Coming soon... | ||
|
||
Link to live demo: | ||
|
||
[Custom Fonts](https://devshareacademy.github.io/code-examples-from-my-video-content/phaser-3/native-custom-fonts/index.html) | ||
|
||
## Credit | ||
|
||
The custom fonts that were used in this demo were created by [Kenney](https://www.kenney.nl/assets/kenney-fonts) and [CodeMan38](https://fonts.google.com/?query=CodeMan38). |
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Phaser 3 - Custom Fonts With Native Phaser!</title> | ||
<style> | ||
html, | ||
body, | ||
.container { | ||
margin: 0px; | ||
height: 100vh; | ||
width: 100vw; | ||
overflow: hidden; | ||
background: #d7d7d7; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
</style> | ||
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script> | ||
</head> | ||
<body> | ||
<div class="container" id="game-container"></div> | ||
<script type="module" src="src/main.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "es6", | ||
"target": "es6", | ||
"checkJs": true | ||
} | ||
} |
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 @@ | ||
export default window.Phaser; |
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,58 @@ | ||
import Phaser from './lib/phaser.js'; | ||
|
||
class MainScene extends Phaser.Scene { | ||
constructor() { | ||
super(MainScene.name); | ||
} | ||
|
||
preload() { | ||
this.load.font( | ||
'Kenney-Future-Narrow', | ||
'assets/fonts/Kenney-Future-Narrow.ttf', | ||
'truetype' | ||
); | ||
this.load.font( | ||
'PressStart2P', | ||
'https://raw.githubusercontent.com/google/fonts/refs/heads/main/ofl/pressstart2p/PressStart2P-Regular.ttf', | ||
'truetype' | ||
); | ||
} | ||
|
||
create() { | ||
const w = this.scale.width / 2; | ||
this.add | ||
.text(w, 100, 'Default Font Family', { | ||
fontSize: 40, | ||
color: '#ffffff', | ||
}) | ||
.setOrigin(0.5); | ||
this.add | ||
.text(w, 200, 'Press Start 2P', { | ||
fontSize: 40, | ||
color: '#ffffff', | ||
fontFamily: 'PressStart2P', | ||
}) | ||
.setOrigin(0.5); | ||
this.add | ||
.text(w, 300, 'Kenny Future Narrow', { | ||
fontSize: 40, | ||
color: '#ffffff', | ||
fontFamily: 'Kenney-Future-Narrow', | ||
}) | ||
.setOrigin(0.5); | ||
} | ||
} | ||
|
||
const gameConfig = { | ||
type: Phaser.CANVAS, | ||
pixelArt: true, | ||
scale: { | ||
parent: 'game-container', | ||
width: 800, | ||
height: 480, | ||
}, | ||
backgroundColor: '#5c5b5b', | ||
scene: [MainScene], | ||
}; | ||
|
||
const game = new Phaser.Game(gameConfig); |
118,425 changes: 118,425 additions & 0 deletions
118,425
phaser-3/3.87/custom-fonts/src/types/phaser.d.ts
Large diffs are not rendered by default.
Oops, something went wrong.