AFrame: how to add a touch event listener to an entity

谁说我不能喝 提交于 2019-12-12 02:22:22

问题


In mobile browser, I want to do something when user touches an image, but I don't know how to use touch listeners. Is there some components that I can use? Or give me some idea how to do it on my own.


回答1:


A-Frame supports DOM events very similarly to web normal pages. Example:

<a-scene>
  <!-- Target -->
  <a-box id="target" material="color: green"></a-box>

  <!-- Camera + Cursor -->
  <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-scene>

And then in JavaScript:

var targetEl = document.querySelector('#target');
targetEl.addEventListener('click', function() {
  targetEl.setAttribute('material', {color: 'red'});
});

See A-Frame's cursor component documentation for more details.



来源:https://stackoverflow.com/questions/43154929/aframe-how-to-add-a-touch-event-listener-to-an-entity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!