默认光标
例如,我们可以创建一个固定在屏幕中心的环形光标。要将光标固定到屏幕上,无论我们在哪里看光标都始终存在,我们将其作为活动相机实体的子项。我们将它放在负 Z 轴上,将它拉到相机前面。当光标点击该框时,我们可以收听 click 事件。
<a-entity camera>
<a-entity cursor="fuse: true; fuseTimeout: 500"
position="0 0 -1"
geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03"
material="color: black; shader: flat">
</a-entity>
</a-entity>
<a-entity id="box" cursor-listener geometry="primitive: box" material="color: blue">
</a-entity>
// Component to change to random color on click.
AFRAME.registerComponent('cursor-listener', {
init: function () {
var COLORS = ['red', 'green', 'blue'];
this.el.addEventListener('click', function (evt) {
var randomIndex = Math.floor(Math.random() * COLORS.length);
this.setAttribute('material', 'color', COLORS[randomIndex]);
console.log('I was clicked at: ', evt.detail.intersection.point);
});
}
});