screen-display

This component can be used to position elements directly on screen in A-Frame.

Given that every object in an A-Frame scene must exist in 3D space, this is in fact achieved by positioning the objects extremely close to the camera, and adjusting the scale and position appropriately.

This component does the hard work of figuring out what “appropriately” means, allowing you to specify a screen position in terms of a percentage of the total screen, or a number of CSS pixels.

It also allows flexibility in whether or not aspect ratios are preserved. See “Component Interface” for more details.

Status

This component is still under development. Particular areas that still need work include:

Installation

Via CDN

<script src="https://cdn.jsdelivr.net/npm/aframe-screen-display@0.1.1/index.min.js"></script>

Or via npm

npm install aframe-screen-display

Usage Guidelines

This component should only be set on objects that are children of the scene’s camera.

If you set it on other objects, it will move & scale the objects in unexpected ways, most likely rendering them invisible!

If you set the screen-display component on an object, do not set the position or scale attributes

See the examples for some examples of how to use the component, or read the detailed interface documentation below.

Component Interface

The following attributes are supported on the screen-display component:

Other Notes

By default, the A-Frame text component positions text 1mm (0.001m in front of the parent object), which in most cases gives the appearance of text directly positioned on the object.

See: https://aframe.io/docs/1.2.0/primitives/a-text.html#attributes_z_offset

For objects that are very close to the camera, this 1mm becomes visible, and can make the text look incorrectly positioned.

To workaround this, set the zOffset attribute on the text component to a much smaller value (e.g. 0.000001).

See the examples folder for some examples of this.