我有一个太空船模型,我想要动画起飞。我希望它是这样的动画将激活,一旦我点击飞船与我的光标。我有动画工作使用,但我希望它激活光标点击事件。下面是我的HTML以及我被JS卡住的地方
<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);
});
}
});发布于 2018-03-17 19:53:05
我会尝试将'begin‘属性添加到动画标记:https://aframe.io/docs/0.8.0/core/animations.html#begin
<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>https://stackoverflow.com/questions/49341124
复制相似问题