首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将js onclick事件添加到aframe动画中

如何将js onclick事件添加到aframe动画中
EN

Stack Overflow用户
提问于 2018-03-17 19:35:56
回答 1查看 2.5K关注 0票数 0

我有一个太空船模型,我想要动画起飞。我希望它是这样的动画将激活,一旦我点击飞船与我的光标。我有动画工作使用,但我希望它激活光标点击事件。下面是我的HTML以及我被JS卡住的地方

代码语言:javascript
复制
<a-entity id="spaceship" cursor-animator gltf-model="models/spaceship.gltf" position="-20 -0.855 -5.259" scale="2 2 2" rotation="0 180 0">
  <a-animation attribute="position" from="-20 0 -5" to="-20 0 -25" dur="10000"></a-animation>
  <a-animation attribute="position" from="-20 0 -25" to="-20 1000 -200" delay="9000" dur="9000"></a-animation>
</a-entity>


// Component to activate spaceship animation on click
AFRAME.registerComponent('cursor-animator', {
init: function () {
this.el.addEventListener('click', function (evt) {
    //Code
  console.log('I was clicked at: ', evt.detail.intersection.point);
});
}
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-17 19:53:05

我会尝试将'begin‘属性添加到动画标记:https://aframe.io/docs/0.8.0/core/animations.html#begin

代码语言:javascript
复制
<a-entity id="camera" camera look-controls cursor="rayOrigin: mouse"></a-entity>
<a-entity id="spaceship" cursor-animator gltf-model="models/spaceship.gltf" position="-20 -0.855 -5.259" scale="2 2 2" rotation="0 180 0">
  <a-animation begin="click" attribute="position" from="-20 0 -5" to="-20 0 -25" dur="10000"></a-animation>
  <a-animation begin="click" attribute="position" from="-20 0 -25" to="-20 1000 -200" delay="9000" dur="9000"></a-animation>
</a-entity>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49341124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档