如何使用一个事件来选择查询选择器选择一个实体复制另一个实体的旋转?

问题描述 投票:1回答:1

在这部分代码中,我想使用一个事件来选择所谓的“名”的变量的含义,选择哪一个实体将复制另一个实体旋转作为用户观看。

不同的事件将导致不同的旋转。

所以,事件1是指名称等于querySelector对象A

然后,我想有行获得它自己的旋转,并给它命名的(地)的动画,然后通过发射moveobject至名启动名的动画。

不过我目前停留在这个问题上投入很多时间试图解决它之后。救命?

    AFRAME.registerComponent("comp", {
       init: function () {
           let name = {}
           this.el.addEventListener("event1", (e) => {
             name = document.querySelector('#objectA');
             console.log('event1')
// line 13?   comp.emit('rowstart)
           });
           this.el.addEventListener("event2", (e) => {
             name = document.querySelector('#objectB');
             console.log('event2')
           });

           let row = document.querySelector('#rowA');
           row.addEventListener('rowstart', function (e) {
               var rotation = row.getAttribute('rotation')
               name.setAttribute('animation', {
                   to: {
                       x: rotation.x,
                       y: rotation.y,
                       z: rotation.z - 30
                   }
               })
           name.emit('moveobject')
           });
       }
   });

我应该指出,低于这个链接是我的代码看起来,当它仅仅是抄袭旋转,而不是使用一个事件来选择哪些实体将被旋转https://glitch.com/edit/#!/copy-rotation?path=index.html:37:8像(编辑)

aframe
1个回答
0
投票

to不是一个向量属性,你必须把它作为一个字符串传递。

name.setAttribute('animation', 'to', `${rotation.x} ${rotation.y} ${rotation.z}`);
© www.soinside.com 2019 - 2024. All rights reserved.