@@ -56,48 +56,41 @@ Here's a super-simple Hello World example - a spinning cube!
56
56
<canvas id =' application' ></canvas >
57
57
<script >
58
58
// create a PlayCanvas application
59
- var canvas = document .getElementById (' application' );
60
- var app = new pc.Application (canvas, { });
61
- app .start ();
59
+ const canvas = document .getElementById (' application' );
60
+ const app = new pc.Application (canvas);
62
61
63
62
// fill the available space at full resolution
64
63
app .setCanvasFillMode (pc .FILLMODE_FILL_WINDOW );
65
64
app .setCanvasResolution (pc .RESOLUTION_AUTO );
66
65
67
66
// ensure canvas is resized when window changes size
68
- window .addEventListener (' resize' , function () {
69
- app .resizeCanvas ();
70
- });
67
+ window .addEventListener (' resize' , () => app .resizeCanvas ());
71
68
72
69
// create box entity
73
- var cube = new pc.Entity (' cube' );
74
- cube .addComponent (' model' , {
70
+ const box = new pc.Entity (' cube' );
71
+ box .addComponent (' model' , {
75
72
type: ' box'
76
73
});
74
+ app .root .addChild (box);
77
75
78
76
// create camera entity
79
- var camera = new pc.Entity (' camera' );
77
+ const camera = new pc.Entity (' camera' );
80
78
camera .addComponent (' camera' , {
81
79
clearColor: new pc.Color (0.1 , 0.1 , 0.1 )
82
80
});
81
+ app .root .addChild (camera);
82
+ camera .setPosition (0 , 0 , 3 );
83
83
84
84
// create directional light entity
85
- var light = new pc.Entity (' light' );
85
+ const light = new pc.Entity (' light' );
86
86
light .addComponent (' light' );
87
-
88
- // add to hierarchy
89
- app .root .addChild (cube);
90
- app .root .addChild (camera);
91
87
app .root .addChild (light);
92
-
93
- // set up initial positions and orientations
94
- camera .setPosition (0 , 0 , 3 );
95
88
light .setEulerAngles (45 , 0 , 0 );
96
89
97
- // register a global update event
98
- app .on (' update' , function ( deltaTime ) {
99
- cube . rotate ( 10 * deltaTime, 20 * deltaTime, 30 * deltaTime);
100
- } );
90
+ // rotate the box according to the delta time since the last frame
91
+ app .on (' update' , dt => box . rotate ( 10 * dt, 20 * dt, 30 * dt));
92
+
93
+ app . start ( );
101
94
</script >
102
95
</body >
103
96
</html >
0 commit comments