A-Frame相机旋转和移动动画不考虑新数据

时间:2018-02-10 23:59:51

标签: javascript animation aframe

我正在尝试让我的相机移动并旋转到以js动态给出的某些位置和旋转。

然而,相机从起始值旋转到0 0 0.当数据显示它应该是其他值。旋转立即完成,没有动画。即使数据成功更改,位置也不会改变。

我正在使用aframe-animation-component。

// JS
var camera = document.getElementById('camera');

camera.components.animation__movecamera.data.from = camera.components.position.data;
camera.components.animation__rotatecamera.data.from = camera.components.rotation.data;

camera.components.animation__movecamera.data.to = (positions.x - positionX)+ ' ' + positions.y + ' ' + (positions.z + 10);
camera.components.animation__rotatecamera.data.to = rotations.x + ' ' + rotations.y + ' ' + rotations.z;

camera.emit('rotateCamera');
camera.emit('moveCamera');


// HTML
<a-camera id="camera"
    look-controls
    wasd-controls="acceleration:200"
    animation__rotateCamera="property: rotation; startEvents: rotateCamera;"
    animation__moveCamera="property: position; startEvents: moveCamera;"
>

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

不应直接访问data属性,它是组件的内部变量。必须使用公共API:

$.each(bookingsData, function (index, onedata) {
                    bookingdatahtml = bookingdatahtml 
                        + '<tr>'
                        + '<td class="actions-cell"><a class="link icon-only" onclick="EditThis(' + onedata.bookings_id + ')" href="javascript:void(0)">' + composeIcon + '</a>'
                        + '<a class="link icon-only" onclick="DeleteThis(' + onedata.bookings_id + ')" href="javascript:void(0)">' + trashIcon + '</a>'
                        + '</td >'
                        + '</tr>'
                }); 
$$('#showBookingbyUserId').html(bookingdatahtml);

文档中的更多详细信息:

https://aframe.io/docs/0.7.0/introduction/javascript-events-dom-apis.html#updating-a-component-with-setattribute