Cardboard click (magnet) does not work

In my aframe project, I want to control the speed with a magnetic cardboard button => start / stop with a cardboard button.

On my desktop and phone, the click event works as I want, but if I put my iphone in cardboard, the click button does not fire. If I touch my finger on the stage, it will work ...

Does the cursor require any settings to access the cardboard button? I tested the button in the Google Cardboard app and it worked.

Here is a small example of what I have. You can see the click event in the console.

    <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Click Test</title>
    <script src="https://aframe.io/releases/0.7.1/aframe.min.js"></script>
    <script src="https://unpkg.com/aframe-extras.ocean@3.13.1/dist/aframe-extras.ocean.min.js"></script>
    <script>
    AFRAME.registerComponent("start-click", {
        init: function() {

            this.el.addEventListener("click", function() {
                console.log("clicked in the scene")
            });
        }
        });
    </script>
</head>

<body>
    <a-scene start-click>
        <!-- sky + ocean -->
        <a-sky radius="100" color="tomato" position="0 -6 0 "></a-sky>
        <a-ocean id="ocean" width="200" depth="200" density="200" position="0 0 0"></a-ocean>

        <!-- camera + cursor. -->
        <a-camera id="camera" position="0 20 80 " fly wasd-controls-enabled="false">
            <a-cursor fuse="false" id="cursor" color="black"></a-cursor>
        </a-camera>
    </a-scene>
    <script>
        document.querySelector("a-scene").enterVR();
    </script>
</body>

</html>
0
source share
3 answers

, . , - :

AFRAME.registerComponent("start-click", {
    init: function() {
        const sceneEl = this.el.sceneEl
        const canvasEl = sceneEl.canvas
        const camera = document.querySelector('a-camera')
        this.isMoving = false
        this.position = {x: 0, y: 20, z: 80}

        canvasEl.addEventListener('touchstart', () => {
            this.isMoving = true
        })

        canvasEl.addEventListener('touchend', () => {
            this.isMoving = false
        })
    },
    tick: function () {
      if (this.isMoving) {
        this.position.z -= 1
        camera.setAttribute('position', this.position)
      }
    }
});

:

https://github.com/donmccurdy/aframe-extras/blob/master/src/controls/touch-controls.js

0

1- -. 2 .

0

, , , : API

In addition, I tried the Noam Almosnino demo with Pixel and Cardboard, and it only registered touch input, but not magnetic input, as expected. I don’t think Don McCurdy’s versatile controls are enough to track a magnetic switch. You can consider this alternative , also provided by Don McCurdy. Sorry, I could not give you the full answer, but I hope this helps you in something.

0
source

All Articles