-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloud.js
37 lines (30 loc) · 818 Bytes
/
cloud.js
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
28
29
30
31
32
33
34
35
36
37
(()=>{
"use strict";
AFRAME.registerComponent('cloud', {
schema: {
velocity: {default: 1}
},
init: function () {
// Do something when component first attached.
//console.log('init', this);
this.pos = this.el.object3D.position;
this.w = parseInt(this.el.getAttribute('width'));
},
update: function () {
// Do something when component's data is updated.
//console.log('update', this)
},
remove: function () {
// Do something the component or its entity is detached.
console.log('remove', this)
},
tick: function (time, timeDelta) {
// Do something on every scene tick or frame.
this.pos.x += this.data.velocity;
if (this.pos.x > 1200+this.w) {
this.pos.x = -1200-this.w;
this.pos.z = (Math.random() * 2400) - 1200;
}
}
});
})();