font-awesome-for-phaser 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -39
- package/dist/constants/icons.d.ts +2495 -16
- package/dist/constants/icons.d.ts.map +1 -1
- package/dist/constants/icons.js +1918 -1731
- package/dist/constants/icons.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,54 +16,22 @@ yarn add font-awesome-for-phaser
|
|
|
16
16
|
|
|
17
17
|
First, you must have the free font awesome imported in your page.
|
|
18
18
|
|
|
19
|
-
```
|
|
20
|
-
<!-- As HTML -->
|
|
21
|
-
<link
|
|
22
|
-
rel="preload"
|
|
23
|
-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/webfonts/fa-solid-900.woff2"
|
|
24
|
-
as="font"
|
|
25
|
-
type="font/woff2"
|
|
26
|
-
crossorigin
|
|
27
|
-
/>
|
|
28
|
-
<link
|
|
29
|
-
rel="preload"
|
|
30
|
-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/webfonts/fa-regular-400.woff2"
|
|
31
|
-
as="font"
|
|
32
|
-
type="font/woff2"
|
|
33
|
-
crossorigin
|
|
34
|
-
/>
|
|
35
|
-
<link
|
|
36
|
-
rel="preload"
|
|
37
|
-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/webfonts/fa-brands-400.woff2"
|
|
38
|
-
as="font"
|
|
39
|
-
type="font/woff2"
|
|
40
|
-
crossorigin
|
|
41
|
-
/>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
> **Note:** Browsers only load a web font the first time it is requested. This means that, in Phaser, the very first time you display a Font Awesome icon, you may see a missing character (the "tofu" box) instead of the correct icon. After the font is loaded, subsequent icons will display correctly.
|
|
45
|
-
|
|
46
|
-
To avoid this issue, it is recommended to preload the font files using the `<link rel="preload" ...>` tags shown above **and** to call `loadFont()` before your game starts. This ensures the font is available when Phaser tries to render the icons, preventing the "tofu" character from appearing.
|
|
47
|
-
|
|
48
|
-
Or, you can use our auto import
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
19
|
+
```ts
|
|
51
20
|
import { loadFont } from 'font-awesome-for-phaser';
|
|
21
|
+
import type Phaser from 'phaser';
|
|
22
|
+
|
|
23
|
+
const config: Phaser.Types.Core.GameConfig = {
|
|
24
|
+
//......
|
|
25
|
+
};
|
|
52
26
|
|
|
53
27
|
loadFont().then(() => {
|
|
54
|
-
const config: Phaser.Types.Core.GameConfig = {
|
|
55
|
-
// .....
|
|
56
|
-
};
|
|
57
28
|
new Game(config);
|
|
58
|
-
})
|
|
29
|
+
})
|
|
59
30
|
|
|
60
31
|
// or
|
|
61
32
|
async function startGame() {
|
|
62
33
|
await loadFont();
|
|
63
34
|
|
|
64
|
-
const config: Phaser.Types.Core.GameConfig = {
|
|
65
|
-
// .....
|
|
66
|
-
};
|
|
67
35
|
new Game(config);
|
|
68
36
|
}
|
|
69
37
|
```
|
|
@@ -82,6 +50,8 @@ const iconText = scene.add.text(0, 0, char, {
|
|
|
82
50
|
font: `36px 'FontAwesome'`, // IMPORTANT! The name of the font MUST BE between char ('), if you use `font: '36px FontAwesome', won't work
|
|
83
51
|
color: '#ffffff',
|
|
84
52
|
});
|
|
53
|
+
// PS: The font should be 'FontAwesome', or 'Font Awesome 7 Free' or 'Font Awesome 7 Brands'. Depends of the char
|
|
54
|
+
|
|
85
55
|
iconText.setOrigin(0.5);
|
|
86
56
|
scene.add.existing(iconText);
|
|
87
57
|
|
|
@@ -91,8 +61,13 @@ import { IconText } from 'font-awesome-for-phaser';
|
|
|
91
61
|
// PS: `this` is the scene
|
|
92
62
|
const icon = new IconText(this, 90, 90, 'gamepad', 64, {
|
|
93
63
|
color: '#0066cc',
|
|
64
|
+
iconStyle: 'solid', // 'solid' | 'regular' | 'brands';
|
|
94
65
|
});
|
|
95
66
|
this.add.existing(icon); // Don't forget to add in scene
|
|
96
67
|
```
|
|
97
68
|
|
|
98
69
|
<img src="data/image.png" alt="example of button">
|
|
70
|
+
|
|
71
|
+
You can see more icons in our [storybook](https://renatocassino.github.io/phaser-toolkit/?path=/story/font-awesome-for-phaser-icontext--basic).
|
|
72
|
+
|
|
73
|
+
<img src="data/storybook.png" alt="storybook example" />
|