问题
I'm creating a VR Editor using AFRAME... I need to create an event when the user clicks on an element by mouse and to do deferent action when clicking by Aframe camera cursor.
I found the <a-scene cursor="rayOrigin: mouse">
but this would do the same click event on both mouse and cursor click.
is that possible in AFRAME?
回答1:
Discriminate by the cursor element:
AFRAME.registerComponent('on-click', {
init: function () {
var self = this;
this.el.addEventListener('click', function (evt) {
if (self.el.sceneEl === evt.detail.cursorEl) {
console.log("MOUSE");
} else {
console.log("CURSOR");
}
});
}
});
Example: https://glitch.com/edit/#!/winter-sagittarius
来源:https://stackoverflow.com/questions/56321191/how-separate-the-mouse-click-event-and-the-courser-click-event-in-aframe