0

This code works properly in A-frame 0.8.0. But I cannot get camera rotation from EventListner in A-frame 0.8.2. Does anybody have solution?

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="https://aframe.io/releases/0.8.2/aframe.min.js"> </script>
</head>

<body>
    <a-scene>
        <a-box color="tomato" position="0 0 -5"depth="2" height="4" width="0.5"></a-box>
        <a-camera id="camera" ></a-camera>
    </a-scene>
    <script type="text/javascript">  
        var target = document.querySelector('[camera]');
        target.addEventListener('componentchanged', function(event) {
            console.log(target.getAttribute('rotation'));
        });
    </script>
</body>

</html>

1 Answer 1

1

1) you won't grab <a-camera> with the [camera] css selector. Instead you should use document.querySelector(a-camera).

2) It's better to poll the rotation value in a custom component:

AFRAME.registerComponent("foo", {
  tick: function() {
    console.log(this.el.getAttribute("rotation")
  }
})

HTML

<a-camera foo></a-camera>

Check it out in my fiddle

Sign up to request clarification or add additional context in comments.

2 Comments

I see. Thank you so much!
@Kiyu if you don't have further questions feel free to mark the anwser

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.