aframe Components Register a custom A-Frame component


Example

AFRAME.registerComponent (name, definition)

Register an A-Frame component. We must register components before we use them anywhere in . Meaning from an HTML file, components should come in order before .

  • {string} name - Component name. The component’s public API as represented through an HTML attribute name.
  • {Object} definition - Component definition. Contains schema and lifecycle handler methods.

Registering component in foo in your js file e.g foo-component.js

AFRAME.registerComponent('foo', {
  schema: {},
  init: function () {},
  update: function () {},
  tick: function () {},
  remove: function () {},
  pause: function () {},
  play: function () {}
});

Usage of foo component in your scene

<html>
  <head>
    <script src="aframe.min.js"></script>
    <script src="foo-component.js"></script>
  </head>
  <body>
    <a-scene>
      <a-entity foo></a-entity>
    </a-scene>
  </body>
</html>