【问题标题】:Idle animation camera Aframe空闲动画相机 Aframe
【发布时间】:2018-06-10 07:38:18
【问题描述】:

我正在使用 aframe 0.8.2,并且正在尝试添加相机空闲动画(仅适用于旋转组件)。到目前为止我已经做到了:

HTML:

<!-- Camera-->
<a-entity id = "my_c" position="8.435 0 -3.579" > <a-camera></a-camera></a-entity>

Javascript:

var scene = document.getElementById("my_s");
var camera = document.getElementById("my_c"); 
var anime_1 = document.createElement("a-animation"); 

/* Add a time of "not moving" */

    var t;
    window.onload = resetTimer;
    // DOM Events
    document.onkeypress = resetTimer;
    document.onmousedown = resetTimer;


    function standby() {
        console.log("Start standby.");
        anime_1.setAttribute("attribute","rotation");


        console.log(camera.getAttribute("rotation"));
        anime_1.setAttribute("dur", "80000");
        anime_1.setAttribute("to", "0 360 0");
        anime_1.setAttribute("easing", "linear");
        anime_1.setAttribute("repeat", "indefinite");
        camera.appendChild(anime_1);
    }

    function resetTimer() {
        clearTimeout(t);
        t = setTimeout(standby, 3000);

        camera.removeChild(anime_1);

        // 1000 milisec = 1 sec
    }

问题是,我认为我的相机没有上传它的位置和旋转:当我旋转我的相机时,相机空闲动画不会在同一位置开始。

感谢您的支持:)

【问题讨论】:

    标签: javascript html aframe


    【解决方案1】:

    您可以以不同方式处理 fromto 属性:

    ...
    let initCamRotation = camera.getAttribute("rotation")
    let endCamRotation = initCameraRotation
    endCamRotation.y += 360
    anime_1.setAttribute("from", initCamRotation);
    anime_1.setAttribute("to", endCamRotation);
    ....
    


    有点离题,但是animation components 动画可以在给定pauseEvents 时暂停,我会尝试使用它而不是a-animation 实体。这里我不确定你是否可以在动画开始时中断它。

    【讨论】:

    • 我正在尝试使用动画组件来实现。今天晚些时候我会回复你的^^谢谢你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2018-09-22
    • 1970-01-01
    相关资源
    最近更新 更多