export class ColliderComponent {
constructor() {
this.observer = this.mutationObserver();
this.aframe();
}
//Registers the AFRAME component.
aframe(){
const __this = this;
AFRAME.registerComponent('collider', {
schema: {
},
init: function () {
console.log("The element to be observed is:",this.el);
__this.observer.observe(this.el, {characterData:true, subtree:true, attributes: true, attributeFilter: ['position'], childList : true});
},
tick : function(){
console.log(this.el.getObject3D('mesh').position);
}
});
}
private tick(){
}
private mutationObserver() : MutationObserver{
return new MutationObserver(mutations => {
mutations.forEach(mutation => {
console.log("Changed position");
});
});
}
}
我正在创建一个简单的对撞机。我将跟踪具有“对撞机”组件的元素,并使用intersectsBox
. 不幸的是,我似乎无法让 MutationObserver 工作。我宁愿使用这种方法而不是刻度线,因为它会在每帧开始执行它,而不是在元素移动时。
有什么建议么?