Skip to content

Commit 9ebadaa

Browse files
authored
README - Update example code
1 parent 333c4c1 commit 9ebadaa

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

README.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,48 +56,41 @@ Here's a super-simple Hello World example - a spinning cube!
5656
<canvas id='application'></canvas>
5757
<script>
5858
// 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);
6261
6362
// fill the available space at full resolution
6463
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
6564
app.setCanvasResolution(pc.RESOLUTION_AUTO);
6665
6766
// ensure canvas is resized when window changes size
68-
window.addEventListener('resize', function() {
69-
app.resizeCanvas();
70-
});
67+
window.addEventListener('resize', () => app.resizeCanvas());
7168
7269
// 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', {
7572
type: 'box'
7673
});
74+
app.root.addChild(box);
7775
7876
// create camera entity
79-
var camera = new pc.Entity('camera');
77+
const camera = new pc.Entity('camera');
8078
camera.addComponent('camera', {
8179
clearColor: new pc.Color(0.1, 0.1, 0.1)
8280
});
81+
app.root.addChild(camera);
82+
camera.setPosition(0, 0, 3);
8383
8484
// create directional light entity
85-
var light = new pc.Entity('light');
85+
const light = new pc.Entity('light');
8686
light.addComponent('light');
87-
88-
// add to hierarchy
89-
app.root.addChild(cube);
90-
app.root.addChild(camera);
9187
app.root.addChild(light);
92-
93-
// set up initial positions and orientations
94-
camera.setPosition(0, 0, 3);
9588
light.setEulerAngles(45, 0, 0);
9689
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();
10194
</script>
10295
</body>
10396
</html>

0 commit comments

Comments
 (0)