如何从A-Frame中的场景中删除实体或元素?

ngo*_*vin 5 aframe

我正在构建一个监视(in tick)其实体位置的组件,当满足某些条件时,它会从场景中删除该实体.我怎样才能删除部分?

例如:

AFRAME.registerComponent('remove-on-tick', {
  tick: function () {
    if (condition) {
      // Remove entity.
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

ngo*_*vin 9

删除实体与DOM中的实体相同:

entityEl.parentNode.removeChild(entityEl);
Run Code Online (Sandbox Code Playgroud)

如果你有一个球体:

var sphere = document.querySelector('a-sphere');
sphere.parentNode.removeChild(sphere);
Run Code Online (Sandbox Code Playgroud)

在组件中,我们通过以下方式引用实体this.el:

AFRAME.registerComponent('remove-on-tick', {
  tick: function () {
    var entity = this.el;
    if (condition) {
      entity.parentNode.removeChild(entity);
    }
  }
});
Run Code Online (Sandbox Code Playgroud)