Skip to content

Commit f4e877c

Browse files
Adds preload scripts.
1 parent e20524e commit f4e877c

File tree

9 files changed

+151
-17
lines changed

9 files changed

+151
-17
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<script src="src/script-nodes-basic-js/OnPointerDownScript.js"></script>
1515
<script src="src/script-nodes-basic-js/CallbackActionScript.js"></script>
1616
<script src="src/script-nodes/PushActionScript.js"></script>
17+
<script src="src/script-nodes/PreloadBarUpdaterScript.js"></script>
1718
<script src="src/scenes/Preload.js"></script>
1819
<script src="src/scenes/Level.js"></script>
1920
<script src="src/main.js"></script>

lib/phaser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
window.addEventListener('load', function () {
33

44
var game = new Phaser.Game({
5-
width: 800,
6-
height: 600,
5+
width: 1280,
6+
height: 720,
77
type: Phaser.AUTO,
88
backgroundColor: "#242424",
99
scale: {

src/scenes/Level.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Level extends Phaser.Scene {
1717
editorCreate() {
1818

1919
// dino
20-
const dino = this.add.image(400, 218, "dino");
20+
const dino = this.add.image(640, 288, "dino");
2121

2222
// onPointerDownScript
2323
const onPointerDownScript = new OnPointerDownScript(dino);
@@ -26,7 +26,7 @@ class Level extends Phaser.Scene {
2626
new PushActionScript(onPointerDownScript);
2727

2828
// text_1
29-
const text_1 = this.add.text(400, 408, "", {});
29+
const text_1 = this.add.text(640, 478, "", {});
3030
text_1.setOrigin(0.5, 0.5);
3131
text_1.text = "Phaser 3 + Phaser Editor 2D";
3232
text_1.setStyle({ "fontFamily": "Arial", "fontSize": "30px" });

src/scenes/Level.scene

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"settings": {
55
"preloadPackFiles": [],
66
"createMethodName": "editorCreate",
7-
"sceneKey": "Level"
7+
"sceneKey": "Level",
8+
"borderWidth": 1280,
9+
"borderHeight": 720
810
},
911
"displayList": [
1012
{
@@ -15,8 +17,8 @@
1517
"texture": {
1618
"key": "dino"
1719
},
18-
"x": 400,
19-
"y": 218,
20+
"x": 640,
21+
"y": 288,
2022
"list": [
2123
{
2224
"prefabId": "a06ed60b-79f1-4444-bf35-89046f71f954",
@@ -42,8 +44,8 @@
4244
"id": "b2b3dbd5-2106-41fa-8a04-9b511e3401a9",
4345
"label": "text_1",
4446
"components": [],
45-
"x": 400,
46-
"y": 408,
47+
"x": 640,
48+
"y": 478,
4749
"originX": 0.5,
4850
"originY": 0.5,
4951
"text": "Phaser 3 + Phaser Editor 2D",

src/scenes/Preload.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,29 @@ class Preload extends Phaser.Scene {
2323
editorCreate() {
2424

2525
// guapen
26-
const guapen = this.add.image(400, 219, "guapen");
27-
guapen.scaleX = 0.5915891440784282;
28-
guapen.scaleY = 0.5915891440784282;
26+
const guapen = this.add.image(505.0120544433594, 360, "guapen");
27+
guapen.scaleX = 0.32715486817515643;
28+
guapen.scaleY = 0.32715486817515643;
29+
30+
// progressBar
31+
const progressBar = this.add.rectangle(553.0120849609375, 361, 256, 20);
32+
progressBar.setOrigin(0, 0);
33+
progressBar.isFilled = true;
34+
progressBar.fillColor = 14737632;
35+
36+
// preloadUpdater
37+
new PreloadBarUpdaterScript(progressBar);
38+
39+
// progressBarBg
40+
const progressBarBg = this.add.rectangle(553.0120849609375, 361, 256, 20);
41+
progressBarBg.setOrigin(0, 0);
42+
progressBarBg.fillColor = 14737632;
43+
progressBarBg.isStroked = true;
44+
45+
// loadingText
46+
const loadingText = this.add.text(552.0120849609375, 329, "", {});
47+
loadingText.text = "Loading...";
48+
loadingText.setStyle({ "color": "#e0e0e0", "fontFamily": "arial", "fontSize": "20px" });
2949

3050
this.events.emit("scene-awake");
3151
}

src/scenes/Preload.scene

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,62 @@
1818
"texture": {
1919
"key": "guapen"
2020
},
21-
"x": 400,
22-
"y": 219,
23-
"scaleX": 0.5915891440784282,
24-
"scaleY": 0.5915891440784282,
21+
"x": 505.0120544433594,
22+
"y": 360,
23+
"scaleX": 0.32715486817515643,
24+
"scaleY": 0.32715486817515643,
25+
"list": []
26+
},
27+
{
28+
"type": "Rectangle",
29+
"id": "845d4ca6-7417-44fc-97e3-a3bb2fbbdd03",
30+
"label": "progressBar",
31+
"components": [],
32+
"x": 553.0120849609375,
33+
"y": 361,
34+
"originX": 0,
35+
"originY": 0,
36+
"isFilled": true,
37+
"fillColor": "#e0e0e0",
38+
"width": 256,
39+
"height": 20,
40+
"list": [
41+
{
42+
"prefabId": "ca949479-ab4d-45d5-b856-2cbecbd8d127",
43+
"id": "250eaa8f-b143-4e41-9ddf-052dfd99672c",
44+
"label": "preloadUpdater",
45+
"components": [],
46+
"nestedPrefabs": [],
47+
"list": []
48+
}
49+
]
50+
},
51+
{
52+
"type": "Rectangle",
53+
"id": "10e175a4-81b6-449e-9561-6d8ba54d3812",
54+
"label": "progressBarBg",
55+
"components": [],
56+
"x": 553.0120849609375,
57+
"y": 361,
58+
"originX": 0,
59+
"originY": 0,
60+
"fillColor": "#e0e0e0",
61+
"isStroked": true,
62+
"width": 256,
63+
"height": 20,
64+
"list": []
65+
},
66+
{
67+
"type": "Text",
68+
"id": "c4092661-6339-47cf-9fea-8abff3a46e0c",
69+
"label": "loadingText",
70+
"components": [],
71+
"x": 552.0120849609375,
72+
"y": 329,
73+
"text": "Loading...",
74+
"fontFamily": "arial",
75+
"fontSize": "20px",
76+
"color": "#e0e0e0",
2577
"list": []
2678
}
2779
],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
// You can write more code here
3+
4+
/* START OF COMPILED CODE */
5+
6+
class PreloadBarUpdaterScript extends ScriptNode {
7+
8+
constructor(parent) {
9+
super(parent);
10+
11+
/* START-USER-CTR-CODE */
12+
// Write your code here.
13+
/* END-USER-CTR-CODE */
14+
}
15+
16+
/* START-USER-CODE */
17+
18+
19+
awake() {
20+
21+
const fullWidth = this.gameObject.width;
22+
23+
this.scene.load.on(Phaser.Loader.Events.PROGRESS, p => {
24+
25+
this.gameObject.width = fullWidth * p;
26+
});
27+
}
28+
29+
/* END-USER-CODE */
30+
}
31+
32+
/* END OF COMPILED CODE */
33+
34+
// You can write more code here
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"id": "ca949479-ab4d-45d5-b856-2cbecbd8d127",
3+
"sceneType": "PREFAB",
4+
"settings": {
5+
"preloadMethodName": "",
6+
"preloadPackFiles": [],
7+
"createMethodName": ""
8+
},
9+
"displayList": [
10+
{
11+
"type": "ScriptNode",
12+
"id": "00cda4d5-1904-4e5c-b813-c14cc09591aa",
13+
"label": "scriptnode_1",
14+
"components": [],
15+
"list": []
16+
}
17+
],
18+
"plainObjects": [],
19+
"meta": {
20+
"app": "Phaser Editor 2D - Scene Editor",
21+
"url": "https://phasereditor2d.com",
22+
"contentType": "phasereditor2d.core.scene.SceneContentType",
23+
"version": 3
24+
}
25+
}

0 commit comments

Comments
 (0)