-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
28 lines (26 loc) · 1.16 KB
/
timer.js
File metadata and controls
28 lines (26 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// <!-- TIMER -->
AFRAME.registerComponent('timer', {
init: function() {
let sceneEl = document.querySelector('a-scene');
timer = document.createElement('a-entity');
timer.setAttribute('id', 'timer');
timer.setAttribute('text',"value: 0:00; color: #000000; font: mozillavr; letterSpacing: 1; align: center;");
timer.setAttribute('position','0 1.3 0');
timer.setAttribute('scale', '2 2 2');
sceneEl.appendChild(timer);
seconds = 60;
function onTimer() {
timer.setAttribute('text',"value: "+ seconds +"; color: #000000; font: mozillavr; letterSpacing: 1; align: center;");
seconds--;
if (seconds < 0) {
timer.setAttribute('text',"value: GAME OVER; color: #000000; font: mozillavr; letterSpacing: 1; align: center;");
}
else {
setTimeout(onTimer, 1000);
}
}
// We want to make this pausable eventually: https://stackoverflow.com/questions/3969475/javascript-pause-settimeout.
// TODO: Only call this on click of start button and/or change of game state
onTimer()
}
});