Files
junisaber/src/components/wall.js

32 lines
735 B
JavaScript
Raw Normal View History

2018-10-11 22:15:41 -10:00
AFRAME.registerComponent('wall', {
schema: {
speed: {default: 1.0}
},
init: function () {
this.maxZ = 10;
},
2018-10-12 03:51:04 -07:00
pause: function () {
this.el.object3D.visible = false;
2018-10-13 09:41:37 -07:00
this.el.removeAttribute('collidable');
2018-10-12 03:51:04 -07:00
},
2018-10-12 03:52:11 -07:00
play: function () {
this.el.object3D.visible = true;
2018-10-13 09:41:37 -07:00
this.el.setAttribute('collidable', '');
2018-10-12 03:52:11 -07:00
},
2018-10-11 22:15:41 -10:00
tock: function (time, delta) {
this.el.object3D.position.z += this.data.speed * (delta / 1000);
2018-10-13 09:41:37 -07:00
if (this.el.object3D.position.z > this.maxZ) { this.returnToPool(); }
2018-10-11 22:15:41 -10:00
},
returnToPool: function () {
this.el.sceneEl.components.pool__wall.returnEntity(this.el);
2018-10-12 03:52:11 -07:00
this.el.object3D.position.z = 9999;
2018-10-11 22:15:41 -10:00
this.el.pause();
2018-10-13 09:41:37 -07:00
this.el.removeAttribute('collidable');
2018-10-13 17:19:36 -07:00
}
2018-10-11 22:15:41 -10:00
});