Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <script src=""></script>
<script src=""></script>

// spawner component to generate an entity on an event.
AFRAME.registerComponent('spawner', {
  schema: {
    on: { default: 'click' },
    mixin: { default: '' }

   * Add event listener.
  update: function (oldData) {
    this.el.addEventListener(, this.spawn.bind(this));

   * Spawn new entity at entity's current position.
  spawn: function () {
    var el = this.el;
    var entity = document.createElement('a-entity');
    var matrixWorld = el.object3D.matrixWorld;
    var position = new THREE.Vector3();
    var rotation = el.getAttribute('rotation');
    var entityRotation;

    entity.setAttribute('position', position);

    // Have the spawned entity face the same direction as the entity.
    // Allow the entity to further modify the inherited rotation.
    entity.setAttribute('position', position);
    entity.addEventListener('loaded', function () {
      entityRotation = entity.getComputedAttribute('rotation');
      entity.setAttribute('rotation', {
        x: entityRotation.x + rotation.x,
        y: entityRotation.y + rotation.y,
        z: entityRotation.z + rotation.z

// click-listener component to pass window clicks to an entity.
AFRAME.registerComponent('click-listener', {
  init: function () {
    var el = this.el;
    window.addEventListener('click', function () {
      el.emit('click', null, false);

    <img id="enemy-sprite" crossorigin="" src="">

    <script id="enemies" type="text/x-nunjucks-template">
      <a-entity layout="type: circle; radius: 5" position="0 0.5 0">
        <a-animation attribute="rotation" dur="30000" easing="linear" repeat="indefinite" to="0 360 0"></a-animation>

        {% for x in range(num) %}
        <a-image look-at="#player" src="#enemy-sprite" transparent="true"></a-image>
        {% endfor %}
    <!-- Laser. -->
    <a-mixin id="laser"
             geometry="primitive: cylinder; radius: 0.05; translate: 0 -2 0"
             material="color: green; metalness: 0.2; opacity: 0.4; roughness: 0.3"
             rotation="90 0 0"></a-mixin>

  <a-entity template="src: #enemies" data-num="10"></a-entity>

  <!-- Add spawner and click-listener to player. -->
  <a-camera id="player" position="0 1.8 0" spawner="mixin: laser; on: click" click-listener></a-camera>

  <a-sky color="#252243"></a-sky>